Problem: You are given a tree of n nodes. The tree is rooted at node 1, which is not considered as a leaf regardless of its degree.

Each leaf of the tree has one of the two colors: red or blue. Leaf node v initially has color s_{v}.

The color of each of the internal nodes (including the root) is determined as follows. 

  * Let b be the number of blue immediate children, and r be the number of red immediate children of a given vertex. 
  * Then the color of this vertex is blue if and only if b - r ≥ k, otherwise red. 



Integer k is a parameter that is same for all the nodes.

You need to handle the following types of queries: 

  * 1 v: print the color of node v; 
  * 2 v c: change the color of leaf v to c (c = 0 means red, c = 1 means blue); 
  * 3 h: update the current value of k to h. 

Input

The first line of the input consists of two integers n and k (2 ≤ n ≤ 10^{5}, -n ≤ k ≤ n) — the number of nodes and the initial parameter k.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u,v ≤ n), denoting that there is an edge between vertices u and v.

The next line consists of n space separated integers — the initial array s (-1 ≤ s_i ≤ 1). s_{i} = 0 means that the color of node i is red. s_{i} = 1 means that the color of node i is blue. s_{i} = -1 means that the node i is not a leaf.

The next line contains an integer q (1 ≤ q ≤ 10^5), the number of queries.

q lines follow, each containing a query in one of the following queries: 

  * 1 v (1 ≤ v ≤ n): print the color of node v; 
  * 2 v c (1 ≤ v ≤ n, c = 0 or c = 1): change the color of leaf v to c (c = 0 means red, c = 1 means blue). It is guaranteed that v is a leaf; 
  * 3 h (-n ≤ h ≤ n): update the current value of k to h. 

Output

For each query of the first type, print 0 if the color of vertex v is red, and 1 otherwise.

Example

Input


5 2
1 2
1 3
2 4
2 5
-1 -1 0 1 0
9
1 1
1 2
3 -2
1 1
1 2
3 1
2 5 1
1 1
1 2


Output


0
0
1
1
0
1

Note

Figures:

(i) The initial tree 

(ii) The tree after the 3rd query 

(iii) The tree after the 7th query 

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[100000], adjList2[100000];
int s[100000], s2[100000];
int t[100000], x[100000];
int parent[100000][17], depth[100000], disc[100000], order[100000], num = 0;
int doDFS(int u, int p, int d) {
  int i;
  parent[u][0] = p, depth[u] = d, disc[u] = num++, order[num - 1] = u;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (v != p) adjList2[u].push_back(v), doDFS(v, u, d + 1);
  }
  return 0;
}
int logn;
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int i;
  for (i = logn - 1; i >= 0; i--) {
    if ((parent[u][i] != -1) && (depth[parent[u][i]] >= depth[v]))
      u = parent[u][i];
  }
  if (u == v) return u;
  for (i = logn - 1; i >= 0; i--) {
    if (parent[u][i] != parent[v][i]) u = parent[u][i], v = parent[v][i];
  }
  return parent[u][0];
}
int key[100000], blue[100000][2], child[100000];
vector<int> cc[100000][2];
int main() {
  int i;
  int n, k, q, u, v;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    u--, v--;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  for (i = 0; i < n; i++) scanf("%d", &s[i]), s2[i] = s[i];
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &t[i]);
    if (t[i] == 1)
      scanf("%d", &x[i]), x[i]--;
    else if (t[i] == 2) {
      scanf("%d %d", &x[i], &u), x[i]--;
      if (s2[x[i]] == u)
        i--, q--;
      else
        s2[x[i]] = u;
    } else
      scanf("%d", &x[i]);
  }
  int j, b, B = sqrt(q);
  doDFS(0, -1, 0);
  for (i = 1; (1 << i) < n; i++) {
    for (j = 0; j < n; j++) {
      if (parent[j][i - 1] != -1)
        parent[j][i] = parent[parent[j][i - 1]][i - 1];
      else
        parent[j][i] = -1;
    }
  }
  logn = i;
  for (b = 0; b < q; b += B) {
    int e = min(b + B, q);
    vector<int> vv;
    for (i = b; i < e; i++) {
      if (t[i] <= 2) vv.push_back(disc[x[i]]);
    }
    sort(vv.begin(), vv.end());
    int l = vv.size();
    for (i = 1; i < l; i++)
      vv.push_back(disc[lca(order[vv[i - 1]], order[vv[i]])]);
    sort(vv.begin(), vv.end());
    vv.resize(unique(vv.begin(), vv.end()) - vv.begin());
    fill(key, key + n, 0);
    for (i = 0; i < vv.size(); i++) key[order[vv[i]]] = 1;
    for (i = n - 1; i >= 0; i--) {
      u = order[i];
      cc[u][0].clear(), cc[u][1].clear();
      if (key[u]) {
        child[u] = u, blue[u][0] = -n - 1, blue[u][1] = n + 1;
        for (j = 0; j < adjList2[u].size(); j++) {
          v = adjList2[u][j];
          if (child[v] == -1)
            cc[u][0].push_back(blue[v][0]);
          else
            cc[u][1].push_back(v);
        }
        sort(cc[u][0].begin(), cc[u][0].end());
      } else if (adjList2[u].empty())
        child[u] = -1, blue[u][0] = blue[u][1] = s[u] ? n + 1 : -n - 1;
      else {
        child[u] = -1;
        for (j = 0; j < adjList2[u].size(); j++) {
          v = adjList2[u][j];
          if (child[v] != -1) child[u] = child[v];
          cc[u][0].push_back(blue[v][0]), cc[u][1].push_back(blue[v][1]);
        }
        sort(cc[u][0].begin(), cc[u][0].end(), greater<int>());
        sort(cc[u][1].begin(), cc[u][1].end(), greater<int>());
        blue[u][0] = -cc[u][0].size(), blue[u][1] = -cc[u][1].size();
        for (j = 0; j < cc[u][0].size(); j++)
          blue[u][0] = max(
              blue[u][0], min(cc[u][0][j], 2 * (j + 1) - (int)cc[u][0].size()));
        for (j = 0; j < cc[u][1].size(); j++)
          blue[u][1] = max(
              blue[u][1], min(cc[u][1][j], 2 * (j + 1) - (int)cc[u][1].size()));
      }
    }
    for (i = b; i < e; i++) {
      if (t[i] == 1) {
        for (j = vv.size() - 1; j >= 0; j--) {
          int u = order[vv[j]];
          if (!adjList2[u].empty()) {
            int num = 0;
            for (l = 0; l < cc[u][1].size(); l++) {
              int v = cc[u][1][l];
              if (k <= blue[v][s[child[v]]]) num++;
            }
            num += cc[u][0].end() -
                   lower_bound(cc[u][0].begin(), cc[u][0].end(), k);
            s[u] = (k <= 2 * num - (int)adjList2[u].size());
          }
          if (u == x[i]) {
            printf("%d\n", s[u]);
            break;
          }
        }
      } else if (t[i] == 2)
        s[x[i]] ^= 1, blue[x[i]][0] = blue[x[i]][1] = s[x[i]] ? n + 1 : -n - 1;
      else
        k = x[i];
    }
  }
  return 0;
}