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;
constexpr int maxn = 100000;
constexpr int SB = 320;
vector<int> G[maxn + 1];
int c[maxn + 1];
int query[maxn][3];
vector<int> dfp;
int key[maxn + 1], kv[maxn + 1];
vector<int> kidv[maxn + 1];
int par[maxn + 1];
int park[maxn + 1];
vector<int> kidk[maxn + 1];
pair<int, int> path[maxn + 1];
void DFS(int u) {
  for (int v : G[u])
    if (v != par[u]) {
      par[v] = u;
      DFS(v);
    }
  dfp.push_back(u);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 1, u, v; i < n; i += 1) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i += 1) cin >> c[i];
  int q;
  cin >> q;
  for (int i = 0; i < q; i += 1) {
    cin >> query[i][0] >> query[i][1];
    if (query[i][0] == 2) cin >> query[i][2];
  }
  DFS(1);
  for (int L = 0; L < q; L += SB) {
    int R = min(q, L + SB), root = 1;
    vector<int> key_node;
    for (int u : dfp) {
      key[u] = 0;
      kidv[u].clear();
      kidk[u].clear();
    }
    for (int j = L; j < R; j += 1)
      if (query[j][0] != 3) key[query[j][1]] = 2;
    for (int u : dfp)
      if (key[u]) {
        if (key[u] >= 2) {
          root = u;
          key_node.push_back(u);
        }
        key[par[u]] += 1;
      }
    for (int u : dfp)
      if (not key[u]) {
        if (~c[u])
          kv[u] = c[u] ? n + 1 : -n;
        else {
          int L = -n, R = n;
          while (L < R) {
            int M = (L + R - ((L + R) & 1)) / 2;
            int b = 0, r = 0;
            for (int x : kidv[u]) (M < x ? b : r) += 1;
            if (b - r >= M)
              L = M + 1;
            else
              R = M;
          }
          kv[u] = L;
        }
        kidv[par[u]].push_back(kv[u]);
      }
    for (int u : dfp)
      if (key[u] >= 2) {
        path[u] = {-n, n + 1};
        sort(kidv[u].begin(), kidv[u].end());
        if (u == root) continue;
        int p = u;
        while (key[par[p]] < 2) {
          int L = -n, R = n;
          while (L < R) {
            int M = (L + R - ((L + R) & 1)) / 2;
            int r = upper_bound(kidv[u].begin(), kidv[u].end(), M) -
                    kidv[u].begin();
            int b = kidv[u].size() - r;
            (M < path[u].first ? b : r) += 1;
            if (b - r >= M)
              L = M + 1;
            else
              R = M;
          }
          path[u].first = L;
          L = -n, R = n;
          while (L < R) {
            int M = (L + R - ((L + R) & 1)) / 2;
            int r = upper_bound(kidv[u].begin(), kidv[u].end(), M) -
                    kidv[u].begin();
            int b = kidv[u].size() - r;
            (M < path[u].second ? b : r) += 1;
            if (b - r >= M)
              L = M + 1;
            else
              R = M;
          }
          path[u].second = L;
          p = par[p];
        }
        park[u] = par[p];
        kidk[par[p]].push_back(u);
      }
    auto rebuild = [&]() {
      for (int u : key_node)
        if (~c[u])
          kv[u] = c[u] ? n + 1 : -n;
        else {
          int L = -n, R = n;
          while (L < R) {
            int M = (L + R - ((L + R) & 1)) / 2;
            int r = upper_bound(kidv[u].begin(), kidv[u].end(), M) -
                    kidv[u].begin();
            int b = kidv[u].size() - r;
            for (int v : kidk[u])
              (M < (M >= kv[v] ? path[v].first : path[v].second) ? b : r) += 1;
            if (b - r >= M)
              L = M + 1;
            else
              R = M;
          }
          kv[u] = L;
        }
      if (0)
        for (int u : key_node) cout << "kv[" << u << "] = " << kv[u] << endl;
    };
    rebuild();
    for (int i = L; i < R; i += 1)
      if (query[i][0] == 3)
        k = query[i][1];
      else if (query[i][0] == 1)
        cout << (~c[query[i][1]] ? c[query[i][1]] : k < kv[query[i][1]])
             << "\n";
      else {
        c[query[i][1]] = query[i][2];
        rebuild();
      }
  }
  return 0;
}