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 maxn = 100005, maxm = 2005;
int n, m, q, cnt, e, stp;
int val[maxn], a[maxn], p[maxm], start[maxn], to[maxn << 1], then[maxn << 1],
    dfn[maxn], size[maxn], lc[maxn << 2], rc[maxn << 2], lazy[maxn << 2],
    id[maxn];
bitset<maxm> prime, full, now, sum[maxn << 2];
inline void add(int x, int y) { then[++e] = start[x], start[x] = e, to[e] = y; }
void dfs(int x, int last) {
  dfn[x] = ++stp, id[stp] = x, size[x] = 1;
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (y == last) continue;
    dfs(y, x), size[x] += size[y];
  }
}
inline void pushup(int now) { sum[now] = sum[lc[now]] | sum[rc[now]]; }
inline void getlazy(int now, int v) {
  v %= m;
  sum[now] = ((sum[now] << v) & full) | (sum[now] >> (m - v));
  lazy[now] += v, lazy[now] %= m;
}
inline void pushdown(int now) {
  if (lazy[now] == 0) return;
  getlazy(lc[now], lazy[now]), getlazy(rc[now], lazy[now]);
  lazy[now] = 0;
}
void build(int l, int r, int now) {
  if (l == r) {
    val[id[l]] %= m, sum[now].reset();
    sum[now][val[id[l]]] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  lc[now] = now << 1, rc[now] = now << 1 | 1;
  build(l, mid, lc[now]), build(mid + 1, r, rc[now]);
  pushup(now);
}
void update(int l, int r, int now, int L, int R, int v) {
  if (L <= l && r <= R) {
    getlazy(now, v);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(now);
  if (L <= mid) update(l, mid, lc[now], L, R, v);
  if (mid < R) update(mid + 1, r, rc[now], L, R, v);
  pushup(now);
}
bitset<maxm> query(int l, int r, int now, int L, int R) {
  if (L <= l && r <= R) return sum[now];
  int mid = (l + r) >> 1;
  bitset<maxm> res;
  res.reset();
  pushdown(now);
  if (L <= mid) res |= query(l, mid, lc[now], L, R);
  if (mid < R) res |= query(mid + 1, r, rc[now], L, R);
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) full[i] = 1;
  p[1] = 1;
  for (int i = 2; i <= m; i++) {
    if (p[i] == 0) a[++cnt] = i, prime[i] = 1;
    for (int j = 1; j <= cnt; j++) {
      if (i * a[j] > m) break;
      p[i * a[j]] = 1;
      if (i % a[j] == 0) break;
    }
  }
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0), build(1, n, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int t, x, v;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d", &x, &v);
      update(1, n, 1, dfn[x], dfn[x] + size[x] - 1, v);
    }
    if (t == 2) {
      scanf("%d", &x);
      now = prime & query(1, n, 1, dfn[x], dfn[x] + size[x] - 1);
      printf("%d\n", now.count());
    }
  }
  return 0;
}