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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long mod = 1e9 + 7;
void add(long long& a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
long long mul(long long a, long long b) { return (a * b) % mod; }
long long mulmod(long long a, long long b, long long M) {
  if (M <= mod) return mul(a, b);
  long long res = 0;
  while (a > 0) {
    if (a & 1ll) {
      res += b;
      if (res >= M) res -= M;
    }
    a >>= 1;
    b <<= 1;
    if (b >= M) b -= M;
  }
  return res;
}
long long ffmod(long long b, long long exp, long long md = mod) {
  long long res = 1;
  while (exp) {
    if (exp & 1ll) res = (res * b) % md;
    b = (b * b) % md;
    exp /= 2ll;
  }
  return res;
}
void mxupd(pair<int, int>& a, pair<int, int> b) {
  if (a.first > b.first)
    a.second = max(a.second, b.first);
  else {
    a.second = max(a.first, b.second);
    a.first = b.first;
  }
}
const int N = 100010;
const int M = 1001;
const int LN = 20;
bitset<M> tr[4 * N];
int lazy[4 * N];
int st[N], en[N], A[N], B[N];
int sv[M];
vector<int> adj[N];
int m;
int tim = 0;
bitset<M> all, dummy, primes;
void apply(bitset<M>& d, int x) { d = (((d << x) & all) | (d >> (m - x))); }
void prop(int i, int st, int en) {
  apply(tr[i], lazy[i]);
  if (st == en) {
    lazy[i] = 0;
    return;
  }
  lazy[i + i] += lazy[i];
  lazy[i + i] %= m;
  lazy[i + i + 1] += lazy[i];
  lazy[i + i + 1] %= m;
  lazy[i] = 0;
}
void dfs(int i, int p = -1) {
  st[i] = ++tim;
  B[tim] = A[i];
  for (auto ve : adj[i])
    if (p - ve) dfs(ve, i);
  en[i] = tim;
}
void build(int i, int st, int en) {
  if (st == en) {
    tr[i].set(B[st]);
    return;
  }
  int mid = (st + en) >> 1;
  build(i + i, st, mid);
  build(i + i + 1, mid + 1, en);
  tr[i] = (tr[i + i] | tr[i + i + 1]);
}
void upd(int i, int st, int en, int l, int r, int x) {
  if (lazy[i]) prop(i, st, en);
  if (l > en || r < st) return;
  if (l <= st && r >= en) {
    lazy[i] += x;
    if (lazy[i]) prop(i, st, en);
    return;
  }
  int mid = (st + en) >> 1;
  upd(i + i, st, mid, l, r, x);
  upd(i + i + 1, mid + 1, en, l, r, x);
  tr[i] = (tr[i + i] | tr[i + i + 1]);
}
bitset<M> query(int i, int st, int en, int l, int r) {
  if (lazy[i]) prop(i, st, en);
  if (l > en || r < st) return dummy;
  if (l <= st && r >= en) {
    return tr[i];
  }
  int mid = (st + en) >> 1;
  bitset<M> lol = query(i + i, st, mid, l, r);
  if (r > mid) lol = (lol | query(i + i + 1, mid + 1, en, l, r));
  return lol;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j, k, x, q;
  int t = 1;
  cin >> n >> m;
  dummy.reset();
  for (i = 1; i <= n; i++) {
    cin >> A[i];
    A[i] %= m;
  }
  for (i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (i = 0; i <= m - 1; i++) all.set(i);
  for (int i = 2; i < m; i++) {
    if (!sv[i]) {
      for (int j = i + i; j < m; j += i) sv[j] = 1;
      primes.set(i);
    }
  }
  dfs(1, -1);
  assert(tim == n);
  build(1, 1, n);
  cin >> q;
  while (q--) {
    int typ, v;
    cin >> typ;
    if (typ == 1) {
      cin >> v >> x;
      x %= m;
      upd(1, 1, n, st[v], en[v], x);
    } else {
      cin >> v;
      bitset<M> ans = query(1, 1, n, st[v], en[v]);
      ans = (ans & primes);
      cout << ans.count() << "\n";
    }
  }
  return 0;
}