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 MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int M = 1005;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int n, m, Q;
int DL[MX], DR[MX], DFN;
int A[MX], B[MX], sum[MX << 2];
bitset<M> stu[MX << 2], temp, pr;
int Head[MX], erear;
struct Edge {
  int v, nxt;
} E[MX * 2];
void edge_init() {
  erear = 0;
  memset(Head, -1, sizeof(Head));
}
void edge_add(int u, int v) {
  E[erear].v = v;
  E[erear].nxt = Head[u];
  Head[u] = erear++;
}
bool prime_is(int x) {
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) return false;
  }
  return true;
}
void prime_init() {
  pr = 0;
  for (int i = 2; i < m; ++i) {
    if (prime_is(i)) pr.set(i);
  }
}
void DFS(int u, int f) {
  DL[u] = ++DFN;
  B[DFN] = A[u];
  for (int i = Head[u]; ~i; i = E[i].nxt) {
    int v = E[i].v;
    if (v == f) continue;
    DFS(v, u);
  }
  DR[u] = DFN;
}
void push_up(int rt) { stu[rt] = stu[rt << 1] | stu[rt << 1 | 1]; }
void func_right(int rt, int x) {
  stu[rt] = (stu[rt] << x) | (stu[rt] >> (m - x));
}
void push_down(int rt) {
  if (sum[rt]) {
    sum[rt << 1] += sum[rt];
    sum[rt << 1] %= m;
    sum[rt << 1 | 1] += sum[rt];
    sum[rt << 1 | 1] %= m;
    func_right(rt << 1, sum[rt]);
    func_right(rt << 1 | 1, sum[rt]);
    sum[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  sum[rt] = 0;
  if (l == r) {
    stu[rt].reset();
    stu[rt].set(B[l] % m);
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  push_up(rt);
}
void add(int L, int R, int x, int l, int r, int rt) {
  if (L <= l && r <= R) {
    sum[rt] = (sum[rt] + x) % m;
    func_right(rt, x);
    return;
  }
  int m = (l + r) >> 1;
  push_down(rt);
  if (L <= m) add(L, R, x, l, m, rt << 1);
  if (R > m) add(L, R, x, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
bitset<M> query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return stu[rt];
  }
  int m = (l + r) >> 1;
  push_down(rt);
  bitset<M> ret;
  if (L <= m) ret |= query(L, R, l, m, rt << 1);
  if (R > m) ret |= query(L, R, m + 1, r, rt << 1 | 1);
  return ret;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    DFN = 0;
    edge_init();
    prime_init();
    for (int i = 1; i <= n; ++i) A[i] = read();
    for (int i = 1; i <= n - 1; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      edge_add(u, v);
      edge_add(v, u);
    }
    DFS(1, -1);
    build(1, n, 1);
    Q = read();
    while (Q--) {
      int op, a, b;
      op = read();
      a = read();
      if (op == 1) {
        b = read();
        add(DL[a], DR[a], b % m, 1, n, 1);
      } else {
        temp = query(DL[a], DR[a], 1, n, 1);
        printf("%d\n", (int)((temp & pr).count()));
      }
    }
  }
  return 0;
}