{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eProfessor Elephant is a master of data structure. Recently, he invented a perfect data structure to maintain information on a tree. He is very proud of this invention, so he prepared this problem for you.\u003c/p\u003e\u003cp\u003eYou are given a tree with $$$n$$$ nodes. The tree nodes are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th node has an integer value $$$w_i$$$.\u003c/p\u003e\u003cp\u003eInitially, $$$w_i\u003d0$$$ for all $$$i\\in [1,n]$$$.\u003c/p\u003e\u003cp\u003eLet\u0027s denote $$$p(u,v)$$$ as all nodes $$$x$$$ on the shortest path from the $$$u$$$-th node to the $$$v$$$-th node(include $$$u$$$ and $$$v$$$). There will be $$$m$$$ events of $$$7$$$ kinds below:\u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e1 u v k\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n,1\\leq k\\leq 10^5$$$), for all nodes $$$x\\in p(u,v)$$$, change $$$w_x$$$ to $$$w_x+k$$$. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e2 u v k\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n,1\\leq k\\leq 10^8$$$), for all nodes $$$x\\in p(u,v)$$$, change $$$w_x$$$ to $$$w_x\\oplus k$$$, where \"$$$\\oplus$$$\" denotes the bitwise XOR operation. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e3 u v k\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n,1\\leq k\\leq 10^8$$$), for all nodes $$$x\\in p(u,v)$$$, change $$$w_x$$$ to $$$w_x-k$$$. Note that if $$$w_x\u0026lt;k$$$, ignore such $$$x$$$. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e4 u v\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n$$$), ask for the sum of $$$w_x$$$ where $$$x\\in p(u,v)$$$. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e5 u v\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n$$$), ask for the bitwise XOR sum of $$$w_x$$$ where $$$x\\in p(u,v)$$$. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e6 u v\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n$$$), ask for $$$\\max\\{w_x|x\\in p(u,v)\\}-\\min\\{w_x|x\\in p(u,v)\\}$$$. \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003e7 u v k\u003c/span\u003e\u0026nbsp;($$$1\\leq u,v\\leq n,1\\leq k\\leq 10^8$$$), ask for $$$\\min\\{|w_x-k||x\\in p(u,v)\\}$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003ePlease write a program to support these events efficiently.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains an integer $$$T(1\\leq T\\leq 5)$$$, denoting the number of test cases.\u003c/p\u003e\u003cp\u003eIn each test case, there are two integers $$$n,m(1\\leq n\\leq 500000,1\\leq m\\leq 2000)$$$ in the first line, denoting the number of nodes and events.\u003c/p\u003e\u003cp\u003eFor the next $$$n-1$$$ lines, each line contains two integers $$$u$$$ and $$$v$$$, denoting a bidirectional edge between vertex $$$u$$$ and $$$v$$$.\u003c/p\u003e\u003cp\u003eFor the next $$$m$$$ lines, each line describes an event.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each query event, print a single line containing an integer, denoting the answer.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\n5 8\n5 2\n5 1\n2 4\n2 3\n1 4 4 5\n3 4 4 1\n2 3 1 4\n6 3 5\n4 2 5\n5 1 3\n6 5 4\n7 1 4 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n8\n0\n0\n2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}