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 inf = 1e9;
const long long Inf = 1e10;
const int P = 1e9 + 7;
const int N = 100005;
inline int IN() {
  int x = 0;
  int ch = 0, f = 0;
  for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar())
    f = (ch == '-');
  for (; ch >= 48 && ch <= 57; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return f ? (-x) : x;
}
int Pow(int x, int y, int p) {
  int a = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) a = (long long)a * x % p;
  return a;
}
int n, m, a[N];
bitset<2000> t[N << 2], Is;
bitset<2000> tmp, U, res;
int tag[N << 2];
struct edge {
  int v, pre;
} e[N << 1];
int dex, adj[N];
int st[N], ed[N], tim, fa[N], Ind[N];
void dfs(int x) {
  st[x] = ++tim;
  Ind[tim] = x;
  for (int i = adj[x]; i; i = e[i].pre) {
    int v = e[i].v;
    if (v == fa[x]) continue;
    fa[v] = x;
    dfs(v);
  }
  ed[x] = tim;
}
void Shift(int x, int y) {
  if (!y) return;
  tag[x] += y;
  if (tag[x] >= m) tag[x] -= m;
  tmp = t[x];
  tmp <<= y;
  tmp |= (tmp >> m);
  tmp &= U;
  t[x] = tmp;
}
void sep(int x) {
  Shift(x * 2, tag[x]);
  Shift(x * 2 + 1, tag[x]);
  tag[x] = 0;
}
int ql, qr, tg;
void M(int x, int L, int R) {
  if (ql <= L && R <= qr) {
    Shift(x, tg);
    return;
  }
  sep(x);
  if (ql <= ((L + R) >> 1)) M(x * 2, L, ((L + R) >> 1));
  if (((L + R) >> 1) < qr) M(x * 2 + 1, ((L + R) >> 1) + 1, R);
  t[x] = t[x * 2] | t[x * 2 + 1];
}
void Q(int x, int L, int R) {
  if (ql <= L && R <= qr) {
    res |= t[x];
    return;
  }
  sep(x);
  if (ql <= ((L + R) >> 1)) Q(x * 2, L, ((L + R) >> 1));
  if (((L + R) >> 1) < qr) Q(x * 2 + 1, ((L + R) >> 1) + 1, R);
}
void B(int x, int L, int R) {
  if (L == R) {
    t[x][a[Ind[L]] % m] = 1;
    return;
  }
  B(x * 2, L, ((L + R) >> 1));
  B(x * 2 + 1, ((L + R) >> 1) + 1, R);
  t[x] = t[x * 2] | t[x * 2 + 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(0); i < (int)(m); i++) U[i] = 1;
  for (int i = (int)(1); i <= (int)(n); i++) a[i] = IN();
  for (int i = (int)(2); i < (int)(m); i++) {
    int fg = 1;
    for (int j = (int)(2); j < (int)(i); j++)
      if (i % j == 0) fg = 0;
    Is[i] = fg;
  }
  for (int i = (int)(1); i < (int)(n); i++) {
    int x = IN(), y = IN();
    e[++dex] = (edge){y, adj[x]};
    adj[x] = dex;
    e[++dex] = (edge){x, adj[y]};
    adj[y] = dex;
  }
  dfs(1);
  B(1, 1, n);
  for (int q = IN(); q; q--) {
    int op = IN(), qx = IN();
    ql = st[qx], qr = ed[qx];
    if (op == 1) {
      tg = IN() % m;
      M(1, 1, n);
    } else {
      res.reset();
      Q(1, 1, n);
      int an = (res & Is).count();
      printf("%d\n", an);
    }
  }
  return 0;
}