1 #include<bits/stdc++.h>
2 using namespace std;
3 #define rep(i,a,b) for(int i=a;i<=b;i++)
4 #define Rep(i,a,b) for(int i=a;i>=b;i--)
5 #define ms(i,a) memset(a,i,sizeof(a))
6 int const N = 100000 + 3;
7 template<class T>void read(T &x) {
8 x = 0;
9 char c = 0;
10 while(!isdigit((c))) c = getchar();
11 while(isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
12 }
13 struct edge {
14 int to, nt;
15 } e[N << 2];
16 struct block {
17 int a[300], num;
18 void ins(int x) {
19 num++;
20 int j = num - 1;
21 while(j && a[j] > x) a[j + 1] = a[j], j--;
22 a[j + 1] = x;
23 }
24 void modify(int x, int y) {
25 int t = lower_bound(a + 1, a + num + 1, x) - a;
26 rep(i, t + 1, num) a[i - 1] = a[i];
27 num--;
28 ins(y);
29 }
30 int query(int x) {
31 return num - (upper_bound(a + 1, a + num + 1, x) - a) + 1;
32 }
33 } b[10000];
34 int h[N], cnt, H[N], bl[N], n, m, a[N], sz, sum, ans,f[N];
35 void add(int a, int b) {
36 e[++cnt].to = b;
37 e[cnt].nt = h[a];
38 h[a] = cnt;
39 }
40 void Add(int a, int b) {
41 e[++cnt].to = b;
42 e[cnt].nt = H[a];
43 H[a] = cnt;
44 }
45 void dfs(int x) {
46 if(b[bl[f[x]]].num >= sz) {
47 bl[x] = ++sum;
48 b[sum].ins(a[x]);
49 Add(bl[f[x]], sum);
50 } else {
51 bl[x] = sum;
52 b[sum].ins(a[x]);
53 }
54 for(int i = h[x]; i; i = e[i].nt) {
55 int v = e[i].to;
56 if(v == f[x]) continue;
57 f[v]=x;
58 dfs(v);
59 }
60 }
61 void getblock(int x, int y) {
62 ans += b[x].query(y);
63 for(int i = H[x]; i; i = e[i].nt) {
64 int v = e[i].to;
65 getblock(v, y);
66 }
67 }
68 void getans(int x, int y) {
69 if(a[x] > y) ans++;
70 for(int i = h[x]; i; i = e[i].nt) {
71 int v = e[i].to;
72 if(v == f[x]) continue;
73 if(bl[v] == bl[x]) getans(v, y);
74 else getblock(bl[v], y);
75 }
76 }
77 int main() {
78 read(n);
79 sz = sqrt(n);
80 rep(i, 1, n - 1) {
81 int x, y;
82 read(x);
83 read(y);
84 add(x, y);
85 add(y, x);
86 }
87 rep(i, 1, n) read(a[i]);
88 dfs(1);
89 read(m);
90 while(m--) {
91 int k, x, y;
92 read(k);
93 read(x);
94 read(y);
95 x ^= ans;
96 y ^= ans;
97 if(k == 0) {
98 ans = 0;
99 getans(x,y);
100 printf("%d\n", ans);
101 }
102 if(k == 1) {
103 b[bl[x]].modify(a[x], y);
104 a[x] = y;
105 }
106 if(k == 2) {
107 a[++n] = y;
108 f[n]=x;
109 add(x, n);
110 if(b[bl[x]].num >= sz) {
111 bl[n] = ++sum;
112 b[sum].ins(y);
113 Add(bl[x], sum);
114 } else {
115 bl[n] = bl[x];
116 b[bl[n]].ins(y);
117 }
118 }
119 }
120 return 0;
121 }