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 int mod = 1000000007;
const int maxn = 100010;
const int INF = ~0U >> 1;
const double eps = 1e-9;
void getint(int &ret) {
  char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  ret = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0';
}
bitset<1000> bits[maxn * 4], bitmask, prime;
int addv[maxn * 4];
int l[maxn], r[maxn], nxt[maxn * 2], to[maxn * 2];
int vis[maxn], first[maxn], c[maxn], a[maxn];
int tot, dfs_clock, n, m, q;
void add_edge(int x, int y) {
  nxt[++tot] = first[x];
  first[x] = tot;
  to[tot] = y;
}
void dfs(int x) {
  vis[x] = 1;
  c[++dfs_clock] = x;
  l[x] = dfs_clock;
  for (int i = first[x]; i; i = nxt[i])
    if (!vis[to[i]]) dfs(to[i]);
  r[x] = dfs_clock;
}
void build(int o, int l, int r) {
  if (l == r) {
    bits[o][a[c[l]]] = 1;
    return;
  }
  int mid = l + r >> 1;
  build(o * 2, l, mid);
  build(o * 2 + 1, mid + 1, r);
  bits[o] = (bits[o * 2] | bits[o * 2 + 1]);
}
void pushdown(int o, int l, int r) {
  if (!addv[o]) return;
  int x = addv[o];
  bits[o] = (bits[o] << x) | (bits[o] >> (m - x));
  bits[o] = bits[o] & bitmask;
  addv[o] = 0;
  if (l == r) return;
  addv[o * 2] = (addv[o * 2] + x) % m;
  addv[o * 2 + 1] = (addv[o * 2 + 1] + x) % m;
}
void modify(int o, int l, int r, int ql, int qr, int x) {
  pushdown(o, l, r);
  if (ql <= l && r <= qr) {
    addv[o] = x;
    pushdown(o, l, r);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid)
    modify(o * 2, l, mid, ql, qr, x);
  else
    pushdown(o * 2, l, mid);
  if (mid < qr)
    modify(o * 2 + 1, mid + 1, r, ql, qr, x);
  else
    pushdown(o * 2 + 1, mid + 1, r);
  bits[o] = (bits[o * 2] | bits[o * 2 + 1]);
}
bitset<1000> query(int o, int l, int r, int ql, int qr) {
  pushdown(o, l, r);
  if (ql <= l && r <= qr) return bits[o];
  int mid = l + r >> 1;
  bitset<1000> ret;
  if (ql <= mid)
    ret |= query(o * 2, l, mid, ql, qr);
  else
    pushdown(o * 2, l, mid);
  if (mid < qr)
    ret |= query(o * 2 + 1, mid + 1, r, ql, qr);
  else
    pushdown(o * 2, mid + 1, r);
  return ret;
}
int main() {
  int x, y;
  cin >> n >> m;
  for (int i = 0; i < m; i++) bitmask[i] = 1;
  for (int i = 2; i < m; i++) {
    prime[i] = 1;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0) prime[i] = 0;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] %= m;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add_edge(x, y);
    add_edge(y, x);
  }
  cin >> q;
  dfs(1);
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int opt;
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d%d", &x, &y);
      y %= m;
      int ql = l[x], qr = r[x];
      modify(1, 1, n, ql, qr, y);
    } else {
      scanf("%d", &x);
      bitset<1000> ans = query(1, 1, n, l[x], r[x]);
      ans = ans & prime;
      printf("%d\n", ans.count());
    }
  }
  return 0;
}