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;
namespace Dango {
const int MAXN = 100005, MAXM = 1005;
struct tree {
  int l, r, tag;
  bitset<MAXM> vis;
} t[MAXN << 2];
vector<int> prime;
bitset<MAXM> res, tmp;
bool is_not_prime[MAXM];
int n, m, q;
int val[MAXN];
int head[MAXN], to[MAXN << 1], nxt[MAXN << 1];
int id[MAXN], link[MAXN], size[MAXN];
int ans;
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= (ch == '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
void init() {
  for (int i = 2; i <= m; i++) {
    if (!is_not_prime[i]) prime.push_back(i);
    for (int j = 0; j < prime.size() && i * prime[j] <= m; j++) {
      is_not_prime[i * prime[j]] = true;
      if (!(i % prime[j])) break;
    }
  }
}
void add(int u, int v) {
  static int cnt;
  cnt++;
  to[cnt] = v;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
void dfs(int u, int f) {
  static int cnt;
  cnt++;
  id[u] = cnt;
  link[cnt] = u;
  size[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == f) continue;
    dfs(v, u);
    size[u] += size[v];
  }
}
void build(int a, int l, int r) {
  t[a].l = l;
  t[a].r = r;
  if (l == r) {
    int data = val[link[l]];
    data %= m;
    t[a].vis[data] = true;
    return;
  }
  int mid = (l + r) >> 1;
  build(a << 1, l, mid);
  build(a << 1 | 1, mid + 1, r);
  t[a].vis = t[a << 1].vis | t[a << 1 | 1].vis;
}
void pushdown(int a) {
  int l = a << 1, r = a << 1 | 1, data = t[a].tag % m;
  string st;
  t[l].tag += data;
  t[l].vis = (t[l].vis << data) | (t[l].vis >> (m - data));
  t[l].vis &= tmp;
  t[r].tag += data;
  t[r].vis = (t[r].vis << data) | (t[r].vis >> (m - data));
  t[r].vis &= tmp;
  t[a].tag = 0;
}
void update(int a, int l, int r, int data) {
  if (t[a].l >= l && t[a].r <= r) {
    t[a].tag += data;
    t[a].vis = (t[a].vis << data) | (t[a].vis >> (m - data));
    t[a].vis &= tmp;
    return;
  }
  if (t[a].tag) pushdown(a);
  int mid = (t[a].l + t[a].r) >> 1;
  if (l <= mid) update(a << 1, l, r, data);
  if (r > mid) update(a << 1 | 1, l, r, data);
  t[a].vis = t[a << 1].vis | t[a << 1 | 1].vis;
}
void query(int a, int l, int r) {
  if (t[a].l >= l && t[a].r <= r) {
    res |= t[a].vis;
    return;
  }
  if (t[a].tag) pushdown(a);
  int mid = (t[a].l + t[a].r) >> 1;
  if (l <= mid) query(a << 1, l, r);
  if (r > mid) query(a << 1 | 1, l, r);
}
int work() {
  n = read();
  m = read();
  init();
  for (int i = 1; i <= n; i++) val[i] = read() % m;
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  dfs(1, 0);
  build(1, 1, n);
  q = read();
  for (int i = 0; i < m; i++) tmp[i] = true;
  for (int i = 1; i <= q; i++) {
    int opt = read();
    if (opt == 1) {
      int x = read(), y = read() % m;
      update(1, id[x], id[x] + size[x] - 1, y);
    } else {
      int x = read();
      ans = 0;
      res.reset();
      query(1, id[x], id[x] + size[x] - 1);
      for (int j = 0; j < prime.size(); j++) ans += res[prime[j]];
      printf("%d\n", ans);
    }
  }
  return 0;
}
}  // namespace Dango
int main() { return Dango::work(); }