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 = 5e5 + 7;
const long long maxm = 1000 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const long long mlog = 20;
const long long SQ = 400;
bitset<maxm> seg[4 * maxn];
bitset<maxm> mab, MT;
long long lazy[4 * maxn];
long long st[maxn], en[maxn], pos[maxn], a[maxn];
vector<long long> adj[maxn];
long long n, m = 10;
bool isprime(long long x) {
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
long long timer = 0;
void dfs(long long v, long long par = -1) {
  st[v] = timer, pos[timer++] = v;
  for (long long u : adj[v])
    if (u != par) dfs(u, v);
  en[v] = timer;
}
void BUILD(long long s = 0, long long e = n, long long id = 1) {
  if (e - s < 2) {
    seg[id][a[pos[s]]] = 1;
    return;
  }
  long long mid = (s + e) / 2;
  BUILD(s, mid, id * 2 + 0);
  BUILD(mid, e, id * 2 + 1);
  seg[id] = (seg[id * 2 + 0] | seg[id * 2 + 1]);
}
bitset<maxm> shift(bitset<maxm> id, long long x) {
  bitset<maxm> tmp = (id << x);
  id = tmp ^ (id >> (m - x));
  return id & mab;
}
void add_lazy(long long id, long long x) {
  seg[id] = shift(seg[id], x);
  lazy[id] = (lazy[id] + x) % m;
}
void push(long long s, long long e, long long id) {
  if (lazy[id] == 0) return;
  add_lazy(id * 2 + 0, lazy[id]);
  add_lazy(id * 2 + 1, lazy[id]);
  lazy[id] = 0;
}
void UPDATE(long long l, long long r, long long x, long long s = 0,
            long long e = n, long long id = 1) {
  if (l >= e || r <= s) return;
  if (l <= s && r >= e) {
    add_lazy(id, x);
    return;
  }
  push(s, e, id);
  long long mid = (s + e) / 2;
  UPDATE(l, r, x, s, mid, id * 2 + 0);
  UPDATE(l, r, x, mid, e, id * 2 + 1);
  seg[id] = (seg[id * 2 + 0] | seg[id * 2 + 1]);
}
bitset<maxm> GET(long long l, long long r, long long s = 0, long long e = n,
                 long long id = 1) {
  if (l >= e || r <= s) return MT;
  if (l <= s && r >= e) return seg[id];
  push(s, e, id);
  long long mid = (s + e) / 2;
  return (GET(l, r, s, mid, id * 2 + 0) | GET(l, r, mid, e, id * 2 + 1));
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
  ;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) mab[i] = 1;
  for (long long i = 0; i < maxm; i++) MT[i] = 0;
  vector<long long> primes;
  for (long long i = 2; i <= m; i++)
    if (isprime(i)) primes.push_back(i);
  for (long long i = 0; i < n; i++) cin >> a[i], a[i] %= m;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    adj[v].push_back(u), adj[u].push_back(v);
  }
  dfs(0);
  BUILD();
  long long q;
  cin >> q;
  while (q--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long v, x;
      cin >> v >> x;
      v--;
      x %= m;
      UPDATE(st[v], en[v], x);
    }
    if (type == 2) {
      long long v;
      cin >> v;
      v--;
      bitset<maxm> bs = GET(st[v], en[v]);
      long long res = 0;
      for (auto p : primes)
        if (bs[p] == 1) res++;
      cout << res << "\n";
    }
  }
  return 0;
}