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;
long long int size[100001], arr[100001], b[100001], lazy[4 * 100001], n, m,
    ind[100001], prime[100001];
vector<long long int> o, v[100001];
bitset<1001> tree[4 * 100001];
bitset<1001> empty, all, pr;
void dfs(long long int cur, long long int par) {
  o.push_back(cur);
  size[cur] = 1;
  for (long long int i = 0; i < v[cur].size(); i++) {
    long long int x = v[cur][i];
    if (x == par) continue;
    dfs(x, cur);
    size[cur] += size[x];
  }
}
void seive() {
  for (int i = 2; i <= 1000; i++) {
    if (!prime[i]) {
      pr.set(i);
      for (int j = 2 * i; j <= 1000; j += i) prime[j] = 1;
    }
  }
}
void build(long long int node, long long int a, long long int b) {
  if (a == b) {
    tree[node].set(arr[a]);
    return;
  }
  long long int mid = (a + b) / 2;
  build(2 * node, a, mid);
  build(2 * node + 1, mid + 1, b);
  tree[node] = tree[2 * node] | tree[2 * node + 1];
}
void update(long long int node, long long int a, long long int b,
            long long int l, long long int r, long long int val) {
  if (lazy[node]) {
    lazy[node] %= m;
    tree[node] =
        ((tree[node] << lazy[node]) & all) | (tree[node] >> (m - lazy[node]));
    if (a != b) {
      lazy[2 * node] = (lazy[2 * node] + lazy[node]) % m;
      lazy[2 * node + 1] = (lazy[2 * node + 1] + lazy[node]) % m;
    }
    lazy[node] = 0;
  }
  if (a > b || a > r || b < l) return;
  if (a >= l && b <= r) {
    tree[node] = ((tree[node] << val) & all) | (tree[node] >> (m - val));
    if (a != b) {
      lazy[2 * node] = (lazy[2 * node] + val) % m;
      lazy[2 * node + 1] = (lazy[2 * node + 1] + val) % m;
    }
    return;
  }
  long long int mid = (a + b) / 2;
  update(2 * node, a, mid, l, r, val);
  update(2 * node + 1, mid + 1, b, l, r, val);
  tree[node] = tree[2 * node] | tree[2 * node + 1];
}
bitset<1001> query(long long int node, long long int a, long long int b,
                   long long int l, long long int r) {
  if (lazy[node]) {
    lazy[node] %= m;
    tree[node] =
        ((tree[node] << lazy[node]) & all) | (tree[node] >> (m - lazy[node]));
    if (a != b) {
      lazy[2 * node] = (lazy[2 * node] + lazy[node]) % m;
      lazy[2 * node + 1] = (lazy[2 * node + 1] + lazy[node]) % m;
    }
    lazy[node] = 0;
  }
  if (a > b || a > r || b < l) return empty;
  if (a >= l && b <= r) return tree[node];
  long long int mid = (a + b) / 2;
  return query(2 * node, a, mid, l, r) | query(2 * node + 1, mid + 1, b, l, r);
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  seive();
  long long int i, j, x, y, q, type, val, node;
  cin >> n >> m;
  for (i = 0; i < m; i++) all.set(i);
  empty.reset();
  for (i = 1; i <= n; i++) cin >> b[i];
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  o.push_back(-1);
  dfs(1, -1);
  for (i = 1; i <= n; i++) ind[o[i]] = i;
  for (i = 1; i <= n; i++) arr[i] = b[o[i]] % m;
  build(1, 1, n);
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> node >> val;
      val %= m;
      update(1, 1, n, ind[node], ind[node] + size[node] - 1, val);
    } else {
      cin >> node;
      cout << (query(1, 1, n, ind[node], ind[node] + size[node] - 1) & pr)
                  .count()
           << "\n";
      ;
    }
  }
  return 0;
}