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;
struct node {
  int v;
  int next;
};
bitset<1010> bit[400010];
bitset<1010> pre;
node edge[200010];
int laz[400010];
int val[100010], prime[1010], first[100010], mp1[100010], mp2[100010],
    sum[100010];
int n, mod, q, num;
void init() {
  int i, j;
  prime[0] = 1, prime[1] = 1;
  for (i = 2; i * i < mod; i++) {
    if (prime[i] == 0)
      for (j = i + i; j < mod; j += i) prime[j] = 1;
  }
  for (i = 0; i < mod; i++)
    if (prime[i] == 0) pre.set(i);
}
void addedge(int u, int v) {
  edge[num].v = v;
  edge[num].next = first[u];
  first[u] = num++;
}
void dfs(int cur, int fa) {
  int i, v;
  num++;
  mp1[cur] = num, mp2[num] = cur, sum[cur] = 1;
  for (i = first[cur]; i != -1; i = edge[i].next) {
    v = edge[i].v;
    if (v != fa) {
      dfs(v, cur);
      sum[cur] += sum[v];
    }
  }
}
void pushup(int cur) { bit[cur] = bit[2 * cur] | bit[2 * cur + 1]; }
void pushdown(int cur) {
  int val;
  val = laz[cur];
  if (val != 0) {
    bit[2 * cur] = (bit[2 * cur] << val) | (bit[2 * cur] >> (mod - val));
    laz[2 * cur] = (laz[2 * cur] + val) % mod;
    bit[2 * cur + 1] =
        (bit[2 * cur + 1] << val) | (bit[2 * cur + 1] >> (mod - val));
    laz[2 * cur + 1] = (laz[2 * cur + 1] + val) % mod;
    laz[cur] = 0;
  }
}
void build(int l, int r, int cur) {
  int m;
  if (l == r) {
    bit[cur].set(val[mp2[l]]);
    return;
  }
  m = (l + r) / 2;
  build(l, m, 2 * cur);
  build(m + 1, r, 2 * cur + 1);
  pushup(cur);
}
void update(int pl, int pr, int val, int l, int r, int cur) {
  int m;
  if (pl <= l && r <= pr) {
    bit[cur] = (bit[cur] << val) | (bit[cur] >> (mod - val));
    laz[cur] = (laz[cur] + val) % mod;
    return;
  }
  pushdown(cur);
  m = (l + r) / 2;
  if (pl <= m) update(pl, pr, val, l, m, 2 * cur);
  if (pr > m) update(pl, pr, val, m + 1, r, 2 * cur + 1);
  pushup(cur);
}
bitset<1010> query(int pl, int pr, int l, int r, int cur) {
  bitset<1010> res;
  int m;
  if (pl <= l && r <= pr) return bit[cur];
  pushdown(cur);
  m = (l + r) / 2;
  if (pl <= m) res |= query(pl, pr, l, m, 2 * cur);
  if (pr > m) res |= query(pl, pr, m + 1, r, 2 * cur + 1);
  return res;
}
int main() {
  bitset<1010> res;
  int i, u, v, tp, x;
  scanf("%d%d", &n, &mod);
  init();
  for (i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    val[i] %= mod;
  }
  memset(first, -1, sizeof(first));
  num = 0;
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
  }
  num = 0;
  dfs(1, 0);
  build(1, n, 1);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d", &u, &x);
      x %= mod;
      update(mp1[u], mp1[u] + sum[u] - 1, x, 1, n, 1);
    } else {
      scanf("%d", &u);
      res = query(mp1[u], mp1[u] + sum[u] - 1, 1, n, 1);
      printf("%d\n", (res & pre).count());
    }
  }
  return 0;
}