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;
const int N = 1e5 + 10;
const int M = 1e3 + 10;
const int MAX_SIZE = 3;
int n, m;
vector<int> f[N];
int fa[N];
int l[N], r[N], cnt = 0;
struct Segtree {
  int l, r;
  int lazy;
  bitset<M> k;
} tr[N * 4];
int a[N], da[N];
bitset<M> s, s0;
int prime[M], cntp = 0;
bool check_prime(int x) {
  if (x == 1) return false;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
void Segtree_Pushdown(int id) {
  if (tr[id].l != tr[id].r && tr[id].lazy > 0) {
    if (tr[id].lazy >= m) tr[id].lazy %= m;
    if (tr[id].lazy == 0) {
      return;
    }
    tr[(id << 1)].k = ((tr[(id << 1)].k << tr[id].lazy) |
                       (tr[(id << 1)].k >> (m - tr[id].lazy))) &
                      s0;
    tr[(id << 1 | 1)].k = ((tr[(id << 1 | 1)].k << tr[id].lazy) |
                           (tr[(id << 1 | 1)].k >> (m - tr[id].lazy))) &
                          s0;
    tr[(id << 1)].lazy += tr[id].lazy;
    tr[(id << 1 | 1)].lazy += tr[id].lazy;
    tr[id].lazy = 0;
  }
}
void Segtree_Pushup(int id) {
  if (tr[id].l != tr[id].r) tr[id].k = tr[(id << 1)].k | tr[(id << 1 | 1)].k;
}
void Segtree_Initial(int id, int l, int r) {
  tr[id].l = l;
  tr[id].r = r;
  if (l == r) {
    tr[id].k[da[l]] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  Segtree_Initial((id << 1), l, mid);
  Segtree_Initial((id << 1 | 1), mid + 1, r);
  Segtree_Pushup(id);
}
void Segtree_Updata(int id, int l, int r, int x) {
  if (l > r) return;
  if (tr[id].l == l && tr[id].r == r) {
    tr[id].k = ((tr[id].k << x) | (tr[id].k >> (m - x))) & s0;
    tr[id].lazy += x;
    return;
  }
  Segtree_Pushdown(id);
  int mid = (tr[id].l + tr[id].r) >> 1;
  Segtree_Updata((id << 1), l, min(mid, r), x);
  Segtree_Updata((id << 1 | 1), max(mid + 1, l), r, x);
  Segtree_Pushup(id);
}
void Segtree_GetResult(int id, int l, int r) {
  if (l > r) return;
  if (tr[id].l == l && tr[id].r == r) {
    s = s | tr[id].k;
    return;
  }
  Segtree_Pushdown(id);
  int mid = (tr[id].l + tr[id].r) >> 1;
  Segtree_GetResult((id << 1), l, min(mid, r));
  Segtree_GetResult((id << 1 | 1), max(mid + 1, l), r);
}
void dfs(int u) {
  cnt++;
  l[u] = r[u] = cnt;
  da[cnt] = a[u];
  for (int i = 0; i < f[u].size(); i++)
    if (f[u][i] != fa[u]) {
      fa[f[u][i]] = u;
      dfs(f[u][i]);
      r[u] = max(r[u], r[f[u][i]]);
    }
}
void init() {
  int u, v;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] %= m;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    f[u].push_back(v);
    f[v].push_back(u);
  }
  for (int i = 0; i < m; i++) s0[i] = 1;
  for (int i = 2; i <= m; i++)
    if (check_prime(i)) prime[++cntp] = i;
  dfs(1);
  Segtree_Initial(1, 1, n);
}
void work() {
  int q, ans;
  int type, v, x;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d", &v, &x);
      x %= m;
      if (x != 0) Segtree_Updata(1, l[v], r[v], x);
    } else {
      ans = 0;
      scanf("%d", &v);
      Segtree_GetResult(1, l[v], r[v]);
      for (int j = 1; j <= cntp; j++)
        if (s[prime[j]] == 1) ans++, s[prime[j]] = 0;
      printf("%d\n", ans);
    }
  }
}
int main() {
  init();
  work();
  return 0;
}