#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int MAXN = 3e5+5;
int trie[MAXN*32+1][2];//all values are <=2^31-1, and we need an additional root node
int trieRoot[MAXN];
int trieptr = 0;
int add(int node, int value){
memcpy(trie[++trieptr], trie[node], sizeof trie[0]);//copy root
int cur = trieptr;
int newRoot = cur;
for(int p = 30; p>=0; --p){//all values are <=2^31-1
int bit = (value >> p) &1;
++trieptr;
if(trie[cur][bit] > 0) memcpy(trie[trieptr], trie[trie[cur][bit]], sizeof trie[0]);//copy child
trie[cur][bit] = trieptr;
cur = trieptr;
}
return newRoot;
}
int search(int node, int value){
int cur = node;
int ans = 0;
for(int p = 30; p>=0; --p){//all values are <=2^31-1
int bit = (value >> p) &1;
if(trie[cur][bit]>0){
cur = trie[cur][bit];
ans |= bit<<p;
}else{
cur = trie[cur][!bit];
ans |= (!bit)<<p;
}
}
return ans;
}
int get_id(int x){
static unordered_map<int,int> mp;
if(!mp.count(x)) mp[x]=mp.size();
return mp[x];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N,Q,R, key;
cin >> N >> Q;
cin >> R >> key;
R = get_id(R);
trieRoot[R] = add(0,key);
for (int i = 0; i < N - 1; i++)
{
int u,v,k;
cin >> u >> v >> k;
u = get_id(u);
v = get_id(v);
trieRoot[u] = add(trieRoot[v],k);
}
int last_answer = 0;
for (int i = 0; i < Q; i++)
{
int t;
cin >> t;
// find real value of t
t ^= last_answer;
if (t == 0)
{
int v,u,k;
cin >> v >> u >> k;
// find real values for u, v, and k
u ^= last_answer;
v ^= last_answer;
k ^= last_answer;
//cout<<"Q: "<<t<<" "<<v<<" "<<u<<" "<<k<<endl;
u = get_id(u);
v = get_id(v);
trieRoot[u] = add(trieRoot[v],k);
}
else
{
int v,k;
cin >> v >> k;
// find real values for v, and k
v ^= last_answer;
k ^= last_answer;
//cout<<"Q: "<<t<<" "<<v<<" "<<k<<endl;
v = get_id(v);
// compute the requested values
int min_answer = k^search(trieRoot[v],k);//
int max_answer = k^search(trieRoot[v],~k);//
cout<<min_answer<<" "<<max_answer<<endl;
// update last_answer
last_answer = min_answer ^ max_answer;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZW5kbCAnXG4nCgpjb25zdCBpbnQgTUFYTiA9IDNlNSs1OwppbnQgdHJpZVtNQVhOKjMyKzFdWzJdOy8vYWxsIHZhbHVlcyBhcmUgPD0yXjMxLTEsIGFuZCB3ZSBuZWVkIGFuIGFkZGl0aW9uYWwgcm9vdCBub2RlCmludCB0cmllUm9vdFtNQVhOXTsKaW50IHRyaWVwdHIgPSAwOwppbnQgYWRkKGludCBub2RlLCBpbnQgdmFsdWUpewoJbWVtY3B5KHRyaWVbKyt0cmllcHRyXSwgdHJpZVtub2RlXSwgc2l6ZW9mIHRyaWVbMF0pOy8vY29weSByb290CglpbnQgY3VyID0gdHJpZXB0cjsKCWludCBuZXdSb290ID0gY3VyOwoJZm9yKGludCBwID0gMzA7IHA+PTA7IC0tcCl7Ly9hbGwgdmFsdWVzIGFyZSA8PTJeMzEtMQoJCWludCBiaXQgPSAodmFsdWUgPj4gcCkgJjE7CgkJKyt0cmllcHRyOwoJCWlmKHRyaWVbY3VyXVtiaXRdID4gMCkgbWVtY3B5KHRyaWVbdHJpZXB0cl0sIHRyaWVbdHJpZVtjdXJdW2JpdF1dLCBzaXplb2YgdHJpZVswXSk7Ly9jb3B5IGNoaWxkCgkJdHJpZVtjdXJdW2JpdF0gPSB0cmllcHRyOwoJCWN1ciA9IHRyaWVwdHI7Cgl9CglyZXR1cm4gbmV3Um9vdDsKfQppbnQgc2VhcmNoKGludCBub2RlLCBpbnQgdmFsdWUpewoJaW50IGN1ciA9IG5vZGU7CglpbnQgYW5zID0gMDsKCWZvcihpbnQgcCA9IDMwOyBwPj0wOyAtLXApey8vYWxsIHZhbHVlcyBhcmUgPD0yXjMxLTEKCQlpbnQgYml0ID0gKHZhbHV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