Problem: Yash loves playing with trees and gets especially excited when they have something to do with prime numbers. On his 20th birthday he was granted with a rooted tree of n nodes to answer queries on. Hearing of prime numbers on trees, Yash gets too intoxicated with excitement and asks you to help out and answer queries on trees for him. Tree is rooted at node 1. Each node i has some value ai associated with it. Also, integer m is given.

There are queries of two types:

  1. for given node v and integer value x, increase all ai in the subtree of node v by value x
  2. for given node v, find the number of prime numbers p less than m, for which there exists a node u in the subtree of v and a non-negative integer value k, such that au = p + m·k.

Input

The first of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ 1000) — the number of nodes in the tree and value m from the problem statement, respectively.

The second line consists of n integers ai (0 ≤ ai ≤ 109) — initial values of the nodes.

Then follow n - 1 lines that describe the tree. Each of them contains two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of nodes connected by the i-th edge.

Next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries to proceed.

Each of the last q lines is either 1 v x or 2 v (1 ≤ v ≤ n, 0 ≤ x ≤ 109), giving the query of the first or the second type, respectively. It's guaranteed that there will be at least one query of the second type.

Output

For each of the queries of the second type print the number of suitable prime numbers.

Examples

Input

8 20
3 7 9 8 4 11 7 3
1 2
1 3
3 4
4 5
4 6
4 7
5 8
4
2 1
1 1 1
2 5
2 4


Output

3
1
1


Input

5 10
8 7 5 1 0
1 2
2 3
1 5
2 4
3
1 1 0
1 1 2
2 2


Output

2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int m, tot, cp;
int inp1[100000 + 5], inp[100000 + 5], laz[100000 * 8 + 5], strt[100000 + 5],
    fin[100000 + 5], par[100000 + 5], ord[100000 + 5], prime[1000 + 5];
bool ans[1000 + 5], m1[1000 + 5], vis[100000 + 5];
bitset<1000> se[100000 * 8 + 5];
vector<int> v[100000 + 5];
void rot(bitset<1000>* bs, int pos) {
  bitset<1000> tmp;
  tmp.set();
  tmp >>= (1000 - m);
  tmp &= (*bs);
  tmp >>= (m - pos);
  (*bs) <<= pos;
  (*bs) |= tmp;
}
void init(int node, int b, int e) {
  int i;
  if (b == e) {
    se[node].set(inp1[b]);
    return;
  }
  init(2 * node, b, (b + e) / 2);
  init(2 * node + 1, (b + e) / 2 + 1, e);
  se[node] = (se[2 * node] | se[2 * node + 1]);
}
void update(int node, int b, int e, int i, int j, int val, int u) {
  if (u > 0) {
    rot(&se[node], u);
    laz[node] = (laz[node] + u) % m;
  }
  if (b > j || e < i) {
    return;
  }
  if (b >= i && e <= j) {
    if (val > 0) {
      rot(&se[node], val);
      laz[node] = (laz[node] + val) % m;
    }
    return;
  }
  update(2 * node, b, (b + e) / 2, i, j, val, laz[node]);
  update(2 * node + 1, (b + e) / 2 + 1, e, i, j, val, laz[node]);
  laz[node] = 0;
  se[node] = (se[2 * node] | se[2 * node + 1]);
}
void query(int node, int b, int e, int i, int j, int u) {
  int k;
  if (u > 0) {
    rot(&se[node], u);
    laz[node] = (laz[node] + u) % m;
  }
  if (b > j || e < i) {
    return;
  }
  if (b >= i && e <= j) {
    for (k = 0; k < cp; k++) {
      if (se[node][prime[k]]) {
        if (!ans[prime[k]]) {
          ans[prime[k]] = true;
          tot++;
        }
      }
    }
    return;
  }
  query(2 * node, b, (b + e) / 2, i, j, laz[node]);
  query(2 * node + 1, (b + e) / 2 + 1, e, i, j, laz[node]);
  laz[node] = 0;
  se[node] = (se[2 * node] | se[2 * node + 1]);
}
int main() {
  int n, i, j, a, b, cnt, qu, tp, x, pre;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &inp[i]);
    inp[i] %= m;
  }
  for (i = 3; i * i < m; i += 2) {
    if (m1[i]) {
      continue;
    }
    for (j = 3; i * j < m; j += 2) {
      m1[i * j] = true;
    }
  }
  cp = 0;
  if (2 < m) {
    prime[cp++] = 2;
    for (i = 3; i < m; i += 2) {
      if (!m1[i]) {
        prime[cp++] = i;
      }
    }
  }
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  stack<int> st;
  cnt = 1;
  vis[1] = true;
  st.push(1);
  while (!st.empty()) {
    pre = st.top();
    strt[pre] = cnt;
    fin[pre] = cnt;
    ord[cnt++] = pre;
    st.pop();
    for (i = 0; i < v[pre].size(); i++) {
      j = v[pre][i];
      if (!vis[j]) {
        vis[j] = true;
        par[j] = pre;
        st.push(j);
      }
    }
  }
  for (i = n; i > 1; i--) {
    fin[par[ord[i]]] = max(fin[par[ord[i]]], fin[ord[i]]);
  }
  for (i = 1; i <= n; i++) {
    inp1[strt[i]] = inp[i];
  }
  init(1, 1, n);
  scanf("%d", &qu);
  while (qu--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d", &b, &x);
      update(1, 1, n, strt[b], fin[b], x % m, 0);
    } else {
      scanf("%d", &b);
      memset(ans, 0, sizeof(ans));
      tot = 0;
      query(1, 1, n, strt[b], fin[b], 0);
      printf("%d\n", tot);
    }
  }
  return 0;
}