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;
typedef int arr32[101000];
int js[1110 / 31];
int Mo, n, top, tp, e, T;
arr32 fst, fa, sou, L, R, pri, A;
int mark[101000 << 2];
struct str {
  int v, nex;
} edge[101000 << 1];
struct bits {
  int v[1110 / 31];
  void proc(int k) {
    k %= Mo;
    memcpy(js, v, sizeof(v));
    memset(v, 0, sizeof(v));
    for (int i = 0; i * 31 < Mo; i++) {
      int j = (i * 31 + k) % Mo;
      int res, roof, you, now;
      res = min(31, Mo - i * 31);
      while (true) {
        roof = (j >= ((Mo - 1) / 31) * 31) ? ((Mo - 1) % 31 + 1) : 31;
        you = roof - j % 31;
        now = min(res, you);
        v[j / 31] |= (js[i] & ((1 << now) - 1)) << (j % 31);
        if (res > you) {
          res -= you;
          j = ((j >= ((Mo - 1) / 31) * 31) ? 0 : (j / 31 + 1)) * 31;
          js[i] >>= you;
        } else
          break;
      }
    }
    return;
  }
} bt_now, bt[101000 << 2];
void make_edge(int a, int b) {
  edge[++e].nex = fst[a];
  fst[a] = e;
  edge[e].v = b;
  edge[++e].nex = fst[b];
  fst[b] = e;
  edge[e].v = a;
}
int dfs(int u) {
  L[u] = R[u] = ++top;
  sou[top] = u;
  for (int i = fst[u]; i; i = edge[i].nex) {
    int v = edge[i].v;
    if ((fa[u] == v)) continue;
    fa[v] = u;
    R[u] = dfs(v);
  }
  return R[u];
}
void down(int u, int L, int R) {
  if (!mark[u]) return;
  mark[u] %= Mo;
  bt[u].proc(mark[u]);
  if (L < R) mark[(u << 1)] += mark[u], mark[(u << 1 | 1)] += mark[u];
  mark[u] = 0;
  return;
}
void proc(int u, int L, int R, int l, int r, int v) {
  down(u, L, R);
  if (L == l && R == r) {
    mark[u] += v;
    mark[u] %= Mo;
    down(u, L, R);
    return;
  }
  if (r < (((L + R) >> 1) + 1))
    down((u << 1 | 1), (((L + R) >> 1) + 1), R),
        proc((u << 1), L, ((L + R) >> 1), l, r, v);
  else if (l > ((L + R) >> 1))
    down((u << 1), L, ((L + R) >> 1)),
        proc((u << 1 | 1), (((L + R) >> 1) + 1), R, l, r, v);
  else
    proc((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1), v),
        proc((u << 1 | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r, v);
  for (int i = 0; i <= (Mo - 1) / 31; i++)
    bt[u].v[i] = bt[(u << 1)].v[i] | bt[(u << 1 | 1)].v[i];
}
void query(int u, int L, int R, int l, int r) {
  down(u, L, R);
  if (L == l && R == r) {
    for (int i = 0; i <= (Mo - 1) / 31; i++)
      bt_now.v[i] = bt_now.v[i] | bt[u].v[i];
    return;
  }
  if (r < (((L + R) >> 1) + 1))
    query((u << 1), L, ((L + R) >> 1), l, r);
  else if (l > ((L + R) >> 1))
    query((u << 1 | 1), (((L + R) >> 1) + 1), R, l, r);
  else
    query((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1)),
        query((u << 1 | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r);
  return;
}
void build_tree(int u, int L, int R) {
  if (L == R) {
    bt[u].v[A[sou[L]] / 31] |= (1 << (A[sou[L]] % 31));
    return;
  }
  build_tree((u << 1), L, ((L + R) >> 1));
  build_tree((u << 1 | 1), (((L + R) >> 1) + 1), R);
  for (int i = 0; i <= (Mo - 1) / 31; i++)
    bt[u].v[i] = bt[(u << 1)].v[i] | bt[(u << 1 | 1)].v[i];
  return;
}
int main() {
  scanf("%d %d", &n, &Mo);
  for (int i = 2; i < Mo; i++) {
    bool flag = true;
    for (int j = 2; j < i && flag; j++)
      if (!(i % j)) flag = false;
    if (flag) pri[++tp] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    A[i] %= Mo;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    make_edge(a, b);
  }
  dfs(1);
  build_tree(1, 1, n);
  for (scanf("%d", &T); T; T--) {
    int ch;
    scanf("%d", &ch);
    if (ch == 1) {
      int v, x;
      scanf("%d %d", &v, &x);
      x %= Mo;
      proc(1, 1, n, L[v], R[v], x);
    } else {
      int v;
      scanf("%d", &v);
      memset(bt_now.v, 0, sizeof(bt_now.v));
      query(1, 1, n, L[v], R[v]);
      int ans = 0;
      for (int i = 1; i <= tp; i++)
        ans += (bt_now.v[pri[i] / 31] >> (pri[i] % 31)) & 1;
      printf("%d\n", ans);
    }
  }
  return 0;
}