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 long long MAXN = (1 << 18);
long long n, m;
long long value[MAXN], a[MAXN];
struct node {
  long long lazy;
  bitset<1000> mask;
  node() { lazy = 0; }
  node(long long val) {
    lazy = 0;
    mask.set(val);
  }
};
node temp, broken;
node merge(node l, node r) {
  temp.mask = l.mask | r.mask;
  temp.lazy = 0;
  return temp;
}
bitset<1000> helper_m;
bitset<1000> fh, sh;
struct segment_tree {
  node tr[4 * MAXN];
  void lazy(long long l, long long r, long long idx) {
    tr[idx].lazy %= m;
    if (tr[idx].lazy) {
      fh = (tr[idx].mask >> (m - tr[idx].lazy)) & helper_m;
      sh = (tr[idx].mask << (tr[idx].lazy)) & helper_m;
      tr[idx].mask = fh | sh;
      if (l != r) {
        tr[2 * idx + 1].lazy += tr[idx].lazy;
        tr[2 * idx + 2].lazy += tr[idx].lazy;
      }
      tr[idx].lazy = 0;
    }
  }
  void init(long long l, long long r, long long idx) {
    if (l == r) {
      tr[idx] = node(value[l] % m);
      return;
    }
    long long mid = (l + r) >> 1;
    init(l, mid, 2 * idx + 1);
    init(mid + 1, r, 2 * idx + 2);
    tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
  }
  void update(long long qL, long long qR, long long val, long long l,
              long long r, long long idx) {
    lazy(l, r, idx);
    if (l > qR || r < qL) return;
    if (qL <= l && r <= qR) {
      tr[idx].lazy += val;
      lazy(l, r, idx);
      return;
    }
    long long mid = (l + r) >> 1;
    update(qL, qR, val, l, mid, 2 * idx + 1);
    update(qL, qR, val, mid + 1, r, 2 * idx + 2);
    tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
  }
  node query(long long qL, long long qR, long long l, long long r,
             long long idx) {
    lazy(l, r, idx);
    if (l > qR || r < qL) return broken;
    if (qL <= l && r <= qR) return tr[idx];
    long long mid = (l + r) >> 1;
    return merge(query(qL, qR, l, mid, 2 * idx + 1),
                 query(qL, qR, mid + 1, r, 2 * idx + 2));
  }
};
vector<long long> G[MAXN];
void read() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
}
long long dfs_time = 0;
long long st[MAXN], fi[MAXN];
void dfs(long long u, long long par) {
  st[u] = ++dfs_time;
  value[dfs_time] = a[u];
  long long v, sz = G[u].size();
  for (long long i = 0; i < sz; i++) {
    v = G[u][i];
    if (par != v) dfs(v, u);
  }
  fi[u] = dfs_time;
}
segment_tree t;
bitset<1000> mask_need;
bool seive[MAXN];
void solve() {
  for (long long i = 0; i < m; i++) helper_m[i] = 1;
  for (long long k = 2; k < m; k++)
    if (!seive[k]) {
      mask_need[k] = 1;
      for (long long j = 2 * k; j < m; j += k) seive[j] = true;
    }
  dfs(1, -1);
  t.init(1, dfs_time, 0);
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long type;
    cin >> type;
    if (type == 2) {
      long long u;
      cin >> u;
      cout << (t.query(st[u], fi[u], 1, dfs_time, 0).mask & mask_need).count()
           << '\n';
    } else {
      long long u, val;
      cin >> u >> val;
      t.update(st[u], fi[u], val, 1, dfs_time, 0);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}