import std; struct Node{ long value; long parent = -1; long edge_value; long[] children; } void main(){ auto N = readln.chomp.to!int; auto edge = new long[][][N]; for(auto n = 0; n < N - 1; n++){ auto input = readln.chomp.split(" ").to!(long[]); auto l = input[0] - 1; auto r = input[1] - 1; auto a = input[2]; edge[l] ~= [r, a]; edge[r] ~= [l, a]; } //stderr.writeln(edge); auto nodes = new Node[N]; auto stack = DList!long([0]); while(!stack.empty){ auto node = stack.back; if(nodes[node].children.length == 0){ foreach(e; edge[node]){ if(e[0] == nodes[node].parent) continue; nodes[e[0]].parent = node; nodes[e[0]].edge_value = e[1]; nodes[node].children ~= e[0]; stack.insertBack(e[0]); } if(nodes[node].children.length == 0){ stack.removeBack; } }else{ foreach(c; nodes[node].children){ nodes[node].value ^= nodes[c].value; nodes[node].value ^= nodes[c].edge_value; } stack.removeBack; } } //stderr.writeln(nodes); auto Q = readln.chomp.to!int; for(auto q = 0; q < Q; q++){ auto input = readln.chomp.split(" ").to!(long[]); auto t = input[0]; auto x = input[1] - 1; if(t == 1){ auto parent = nodes[x].parent; auto xor = nodes[x].value ^ nodes[x].edge_value; while(parent >= 0){ nodes[parent].value ^= xor; parent = nodes[parent].parent; } nodes[x].parent = -1; auto queue = DList!long([x]); while(!queue.empty){ auto node = queue.front; queue.removeFront; nodes[node].value = 0; foreach(c; nodes[node].children){ queue.insertBack(c); } } }else{ writeln(nodes[x].value); } //stderr.writeln(nodes); } //stderr.writeln(nodes); }