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;
bitset<1000> prm, ret;
bitset<1000> nd[(4 * 200005) + 2];
vector<int> G[200005 + 2];
int tmm, St[200005 + 2], Ed[200005 + 2], ar[200005 + 2], val[200005 + 2];
int m, mk[200005 + 2];
void Seive(int m) {
  prm.set();
  prm.reset(0);
  prm.reset(1);
  for (int i = 2; i < m; i++) {
    if (prm.test(i)) {
      for (int j = i + i; j < m; j += i) {
        prm.reset(j);
      }
    }
  }
  for (int i = m; i < 1000; i++) prm.reset(i);
}
void Dfs(int u, int p) {
  St[u] = ++tmm;
  val[tmm] = ar[u] % m;
  for (int i = 0; i < (int)(G[u].size()); i++) {
    int v = G[u][i];
    if (v == p) continue;
    Dfs(v, u);
  }
  Ed[u] = tmm;
}
void Build(int id, int l, int r) {
  mk[id] = 0;
  if (l == r) {
    nd[id].set(val[l]);
    return;
  }
  int lft = (id << 1), rgt = lft + 1, md = (l + r) >> 1;
  Build(lft, l, md);
  Build(rgt, md + 1, r);
  nd[id] = (nd[lft] | nd[rgt]);
}
void go(int id, int v) { nd[id] = ((nd[id] << v) | (nd[id] >> (m - v))); }
void Upd(int id, int l, int r, int q1, int q2, int v) {
  if (l == q1 && r == q2) {
    go(id, v);
    mk[id] = (mk[id] + v) % m;
    return;
  }
  int lft = (id << 1), rgt = lft + 1, md = (l + r) >> 1;
  if (mk[id]) {
    int vv = mk[id];
    go(lft, vv);
    go(rgt, vv);
    mk[lft] = (mk[lft] + vv) % m;
    mk[rgt] = (mk[rgt] + vv) % m;
    mk[id] = 0;
  }
  if (q2 <= md)
    Upd(lft, l, md, q1, q2, v);
  else if (q1 > md)
    Upd(rgt, md + 1, r, q1, q2, v);
  else {
    Upd(lft, l, md, q1, md, v);
    Upd(rgt, md + 1, r, md + 1, q2, v);
  }
  nd[id] = (nd[lft] | nd[rgt]);
}
void Qry(int id, int l, int r, int q1, int q2) {
  if (l == q1 && r == q2) {
    ret |= nd[id];
    return;
  }
  int lft = (id << 1), rgt = lft + 1, md = (l + r) >> 1;
  if (mk[id]) {
    int vv = mk[id];
    go(lft, vv);
    go(rgt, vv);
    mk[lft] = (mk[lft] + vv) % m;
    mk[rgt] = (mk[rgt] + vv) % m;
    mk[id] = 0;
  }
  if (q2 <= md)
    Qry(lft, l, md, q1, q2);
  else if (q1 > md)
    Qry(rgt, md + 1, r, q1, q2);
  else {
    Qry(lft, l, md, q1, md);
    Qry(rgt, md + 1, r, md + 1, q2);
  }
}
int n;
int main() {
  int i, j, k, x, y, z, op, q;
  scanf("%d%d", &n, &m);
  Seive(m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    ar[i] %= m;
  }
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  tmm = 0;
  Dfs(1, 0);
  Build(1, 1, n);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &x, &y);
      y %= m;
      Upd(1, 1, n, St[x], Ed[x], y);
    } else {
      scanf("%d", &x);
      ret.reset();
      Qry(1, 1, n, St[x], Ed[x]);
      int ans = (ret & prm).count();
      printf("%d\n", ans);
    }
  }
  return 0;
}