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;
#pragma comment(linker, "/STACK:16777216")
const int inf = 0x3f3f3f3f;
const long double pi = acos(-1.0);
const string debug_line = "yolo";
const double PI = 4 * atan(1);
vector<int> Adj[100001];
bool visited[100001];
int begin1[100001];
int discover[100001];
int size1[100001];
int dfs_timer = 1;
bitset<1000> tree[400010];
int updateTree[400001];
bitset<1000> prime;
int a[100001];
int n, m;
void calc() {
  for (int(i) = (2); (i) < (1000); ++(i)) {
    prime[i] = true;
  }
  for (int(i) = (2); (i) < (1000); ++(i)) {
    if (prime[i]) {
      for (int j = i + i; j < 1000; j = j + i) {
        prime[j] = false;
      }
    }
  }
}
void DFS(int u, int p) {
  visited[u] = true;
  begin1[u] = dfs_timer;
  discover[dfs_timer] = u;
  size1[u] += 1;
  dfs_timer++;
  for (auto &(t1) : (Adj[u])) {
    if (!visited[t1] && t1 != p) {
      DFS(t1, u);
      size1[u] += size1[t1];
    }
  }
}
void initialise(int node, int b, int e) {
  if (b > e) {
    return;
  } else if (b == e) {
    tree[node].set(a[discover[b]] % m, 1);
    return;
  } else {
    initialise(2 * node, b, (b + e) / 2);
    initialise(2 * node + 1, (b + e) / 2 + 1, e);
    tree[node] = tree[2 * node] | tree[2 * node + 1];
  }
}
void make_shift(int node, int val) {
  tree[node] = (tree[node] >> (m - val)) |
               ((tree[node] << (1000 - m + val)) >> (1000 - m));
}
void update(int node, int b, int e, int i, int j, int val) {
  if (updateTree[node] != 0) {
    make_shift(node, updateTree[node] % m);
    if (b != e) {
      updateTree[2 * node] = (updateTree[2 * node] + updateTree[node]) % m;
      updateTree[2 * node + 1] =
          (updateTree[2 * node + 1] + updateTree[node]) % m;
    }
    updateTree[node] = 0;
  }
  if (b > e || i > e || j < b) {
    return;
  } else if (i <= b && e <= j) {
    make_shift(node, val);
    if (b != e) {
      updateTree[2 * node] = (updateTree[2 * node] + val) % m;
      updateTree[2 * node + 1] = (updateTree[2 * node + 1] + val) % m;
    }
    return;
  } else {
    update(2 * node, b, (b + e) / 2, i, j, val);
    update(2 * node + 1, (b + e) / 2 + 1, e, i, j, val);
    tree[node] = tree[2 * node] | tree[2 * node + 1];
  }
}
void query(bitset<1000> &res, int node, int b, int e, int i, int j) {
  if (updateTree[node] != 0) {
    make_shift(node, updateTree[node] % m);
    if (b != e) {
      updateTree[2 * node] = (updateTree[2 * node] + updateTree[node]) % m;
      updateTree[2 * node + 1] =
          (updateTree[2 * node + 1] + updateTree[node]) % m;
    }
    updateTree[node] = 0;
  }
  if (b > e || i > e || j < b) {
    return;
  } else if (i <= b && e <= j) {
    res = tree[node];
    return;
  } else {
    bitset<1000> l;
    bitset<1000> r;
    query(l, 2 * node, b, (b + e) / 2, i, j);
    query(r, 2 * node + 1, (b + e) / 2 + 1, e, i, j);
    res = l | r;
    return;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  calc();
  for (int(i) = (1); (i) < (n + 1); ++(i)) {
    int temp;
    scanf("%d", &temp);
    a[i] = temp;
  }
  for (int(i) = (1); (i) < (n); ++(i)) {
    int a, b;
    scanf("%d%d", &a, &b);
    Adj[a].push_back(b);
    Adj[b].push_back(a);
  }
  DFS(1, 1);
  initialise(1, 1, n);
  int t;
  scanf("%d", &t);
  while (t--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int first, second;
      scanf("%d%d", &first, &second);
      update(1, 1, n, begin1[first], begin1[first] + size1[first] - 1,
             second % m);
    } else if (type == 2) {
      int first;
      scanf("%d", &first);
      bitset<1000> res;
      query(res, 1, 1, n, begin1[first], begin1[first] + size1[first] - 1);
      res = res & prime;
      printf("%d\n", res.count());
    }
  }
  return 0;
}