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;
inline char gc() {
  static char now[1 << 16], *s, *t;
  if (s == t) {
    t = (s = now) + fread(now, 1, 1 << 16, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int read() {
  int x = 0;
  char ch = gc();
  while (ch < '0' || '9' < ch) ch = gc();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = gc();
  return x;
}
int pr[200] = {0,   2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,
               41,  43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,
               101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
               167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
               239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311,
               313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389,
               397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
               467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563,
               569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
               643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
               733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821,
               823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907,
               911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
const int N = 1e5 + 10;
int n, m, a[N];
vector<int> son[N];
void edAdd(int u, int v) { son[u].push_back(v), son[v].push_back(u); }
int dfCnt, dfn[N], fr[N], to[N];
void dfs(int u, int fa) {
  dfn[++dfCnt] = u;
  fr[u] = dfCnt;
  for (int i = 0; i < son[u].size(); i++) {
    int v = son[u][i];
    if (v != fa) dfs(v, u);
  }
  to[u] = dfCnt;
}
int sgCnt, rt, ch[N << 1][2];
bitset<1010> info[N << 1];
int tag[N << 1];
void update(int p) { info[p] = info[ch[p][0]] | info[ch[p][1]]; }
void change(int p, int x) {
  info[p] = (info[p] << x) | (info[p] >> m - x);
  tag[p] = (tag[p] + x) % m;
}
void pushdw(int p) {
  if (tag[p]) change(ch[p][0], tag[p]), change(ch[p][1], tag[p]), tag[p] = 0;
}
void bldTr(int &p, int L0, int R0) {
  if (!p) p = ++sgCnt;
  if (L0 == R0) {
    info[p][a[dfn[L0]]] = 1;
    return;
  }
  int mid = L0 + R0 >> 1;
  bldTr(ch[p][0], L0, mid);
  bldTr(ch[p][1], mid + 1, R0);
  update(p);
}
int optL, optR;
void ins(int p, int L0, int R0, int x) {
  if (optL <= L0 && R0 <= optR) {
    change(p, x);
    return;
  }
  pushdw(p);
  int mid = L0 + R0 >> 1;
  if (optL <= mid) ins(ch[p][0], L0, mid, x);
  if (mid < optR) ins(ch[p][1], mid + 1, R0, x);
  update(p);
}
bitset<1010> resQ;
void query(int p, int L0, int R0) {
  if (optL <= L0 && R0 <= optR) {
    resQ |= info[p];
    return;
  }
  pushdw(p);
  int mid = L0 + R0 >> 1;
  if (optL <= mid) query(ch[p][0], L0, mid);
  if (mid < optR) query(ch[p][1], mid + 1, R0);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read() % m;
  for (int i = 1; i <= n - 1; i++) edAdd(read(), read());
  dfs(1, 0);
  bldTr(rt, 1, n);
  int Q = read();
  while (Q--) {
    int opt = read(), v = read();
    optL = fr[v], optR = to[v];
    if (opt == 1)
      ins(rt, 1, n, read() % m);
    else {
      resQ = 0, query(rt, 1, n);
      int ans = 0;
      for (int i = 1; i <= 168 && pr[i] < m; i++)
        if (resQ[pr[i]]) ans++;
      printf("%d\n", ans);
    }
  }
  return 0;
}