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>
const int M = 1000;
const int N = 100100;
using namespace std;
inline int c1(int n) { return (n << 1); }
inline int c2(int n) { return (n << 1) | 1; }
int n, m;
int num[N];
bool isPrime[M];
int prime_count;
vector<int> primes;
int lazy[8 * N];
bitset<M> T[8 * N];
bitset<M> empty_bitset;
bitset<M> full_bitset;
int len;
bool vis[N];
int open[N];
int close[N];
int euler[2 * N];
vector<int> adj[N];
void build(int node, int st, int end) {
  if (st == end) {
    T[node].reset();
    T[node][num[euler[st]]] = 1;
    return;
  }
  int mid = st + end >> 1;
  build(c1(node), st, mid);
  build(c2(node), mid + 1, end);
  T[node] = T[c1(node)] | T[c2(node)];
}
inline void make_changes(bitset<M> &b, int val) {
  b = (((b << val) | (b >> (m - val))) & full_bitset);
}
void update(int node, int st, int end, int l, int r, int v) {
  if (lazy[node] != 0) {
    make_changes(T[node], lazy[node]);
    if (st != end) {
      lazy[c1(node)] = (lazy[c1(node)] + lazy[node]) % m;
      lazy[c2(node)] = (lazy[c2(node)] + lazy[node]) % m;
    }
    lazy[node] = 0;
  }
  if (st > end || r < st || end < l) return;
  if (l <= st && end <= r) {
    make_changes(T[node], v);
    if (st != end) {
      lazy[c1(node)] = (lazy[c1(node)] + v) % m;
      lazy[c2(node)] = (lazy[c2(node)] + v) % m;
    }
    return;
  }
  int mid = st + end >> 1;
  update(c1(node), st, mid, l, r, v);
  update(c2(node), mid + 1, end, l, r, v);
  T[node] = T[c1(node)] | T[c2(node)];
}
bitset<M> query(int node, int st, int end, int l, int r) {
  if (lazy[node] != 0) {
    make_changes(T[node], lazy[node]);
    if (st != end) {
      lazy[c1(node)] = (lazy[c1(node)] + lazy[node]) % m;
      lazy[c2(node)] = (lazy[c2(node)] + lazy[node]) % m;
    }
    lazy[node] = 0;
  }
  if (st > end || r < st || end < l) return empty_bitset;
  if (l <= st && end <= r) return T[node];
  int mid = st + end >> 1;
  bitset<M> q1 = query(c1(node), st, mid, l, r);
  bitset<M> q2 = query(c2(node), mid + 1, end, l, r);
  return q1 | q2;
}
void sieve() {
  isPrime[0] = isPrime[1] = 1;
  int till = sqrt(m);
  for (int i = 2; i <= till; i++)
    if (!isPrime[i])
      for (int j = i * i; j <= m; j += i) isPrime[j] = 1;
  if (m > 1) primes.push_back(2);
  for (int i = 3; i < m; i += 2)
    if (!isPrime[i]) primes.push_back(i);
  prime_count = primes.size();
}
void dfs(int u) {
  vis[u] = 1;
  euler[len++] = u;
  bool isLeaf = 1;
  int till = adj[u].size();
  for (int i = 0; i < till; i++) {
    int v = adj[u][i];
    if (!vis[v]) {
      isLeaf = 0;
      dfs(v);
    }
  }
  if (!isLeaf) euler[len++] = u;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < M; i++) {
    empty_bitset[i] = 0;
    if (i < m) full_bitset[i] = 1;
  }
  sieve();
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    num[i] %= m;
    open[i] = -1;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  build(1, 0, len - 1);
  for (int i = 0; i < len; i++) {
    int curr = euler[i];
    if (open[curr] == -1) open[curr] = i;
    close[curr] = i;
  }
  int queries;
  cin >> queries;
  while (queries--) {
    int type, vertex;
    cin >> type >> vertex;
    if (type == 1) {
      int val;
      cin >> val;
      val %= m;
      if (val == 0) continue;
      update(1, 0, len - 1, open[vertex], close[vertex], val);
    } else {
      bitset<M> res = query(1, 0, len - 1, open[vertex], close[vertex]);
      int ans = 0;
      for (int i = 0; i < prime_count; i++) ans += res[primes[i]];
      cout << ans << '\n';
    }
  }
  return 0;
}