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>
int min(int a, int b) { return a < b ? a : b; }
int *ej[100000], eo[100000], *ej_[100000], eo_[100000], *dp[100000],
    deg[100000], n;
void append(int i, int j) {
  int o = eo[i]++;
  if (o >= 2 && (o & o - 1) == 0)
    ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);
  ej[i][o] = j;
}
char used[100000];
int cc[100000], jj[100000], kkb[100000], kkr[100000];
int tt[100000], kk[100000], ii[100000], cc_[100000];
void dfs1(int p, int i) {
  int o, j_, k;
  memset(dp[i], 0, deg[i] * 2 * sizeof *dp[i]);
  j_ = -1;
  for (o = eo[i]; o--;) {
    int j = ej[i][o];
    if (j != p) {
      dfs1(i, j);
      if (jj[j] == -1) {
        dp[i][0]++;
        if (kkr[j] <= -deg[i])
          dp[i][0] -= 2;
        else if (kkr[j] <= deg[i])
          dp[i][deg[i] - 1 + kkr[j]] -= 2;
      } else if (j_ == -1)
        j_ = j;
      else
        j_ = -2;
    }
  }
  for (k = 1; k < deg[i] * 2; k++) dp[i][k] += dp[i][k - 1];
  if (j_ == -1 && !used[i]) {
    jj[i] = -1;
    if (deg[i] == 0)
      kkr[i] = cc[i] == 0 ? -0x3f3f3f3f : 0x3f3f3f3f;
    else {
      k = -(deg[i] - 1);
      while (k <= deg[i] && dp[i][k + deg[i] - 1] >= k) k++;
      kkr[i] = k;
    }
  } else if (j_ != -2 && !used[i]) {
    jj[i] = jj[j_];
    k = -(deg[i] - 1);
    while (k <= deg[i] && dp[i][k + deg[i] - 1] + (k <= kkb[j_] ? 1 : -1) >= k)
      k++;
    kkb[i] = k - 1;
    while (k <= deg[i] && dp[i][k + deg[i] - 1] + (k < kkr[j_] ? 1 : -1) >= k)
      k++;
    kkr[i] = k;
  } else {
    jj[i] = i, kkb[i] = -0x3f3f3f3f, kkr[i] = 0x3f3f3f3f, used[i] = 1;
    for (o = eo[i]; o--;) {
      int j = ej[i][o];
      if (j != p && jj[j] != -1) ej_[i][eo_[i]++] = j;
    }
  }
}
int dfs2(int i, int k_) {
  int o, k;
  if (deg[i] == 0) return cc[i];
  if (k_ <= -deg[i]) return 1;
  if (k_ > deg[i]) return 0;
  k = 0;
  for (o = eo_[i]; o--;) {
    int j = ej_[i][o], c = dfs2(jj[j], k_);
    if (k_ <= kkb[j])
      c = 1;
    else if (k_ >= kkr[j])
      c = 0;
    if (c == 1)
      k++;
    else
      k--;
  }
  k += dp[i][deg[i] - 1 + k_];
  return k >= k_;
}
void solve(int hl, int hr) {
  int h;
  memset(used, 0, n * sizeof *used);
  for (h = hl; h < hr; h++)
    if (tt[h] != 3) used[ii[h]] = 1;
  memset(eo_, 0, n * sizeof *eo_);
  dfs1(-1, 0);
  for (h = hl; h < hr; h++)
    if (tt[h] == 1)
      printf("%d\n", dfs2(ii[h], kk[h]));
    else if (tt[h] == 2)
      cc[ii[h]] = cc_[h];
}
int main() {
  int q, k, h, i, j;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) ej[i] = (int *)malloc(2 * sizeof *ej[i]);
  for (h = 0; h < n - 1; h++) {
    scanf("%d%d", &i, &j), i--, j--;
    append(i, j), append(j, i);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &cc[i]);
    deg[i] = i == 0 ? eo[i] : eo[i] - 1;
    ej_[i] = (int *)malloc(deg[i] * sizeof *ej_[i]);
    dp[i] = (int *)malloc(deg[i] * 2 * sizeof *dp[i]);
  }
  scanf("%d", &q);
  for (h = 0; h < q; h++) {
    int x;
    scanf("%d%d", &tt[h], &x);
    if (tt[h] == 1)
      ii[h] = x - 1;
    else if (tt[h] == 2)
      scanf("%d", &cc_[h]), ii[h] = x - 1;
    else
      k = x;
    kk[h] = k;
  }
  for (h = 0; h < q; h += 2000) solve(h, min(h + 2000, q));
  return 0;
}