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 N = 100005, M = 1005;
int n, m, q;
int a[N];
bool isprime[N];
int prime[N], tot;
bitset<M> p, l;
void init(int m) {
  memset(isprime, true, sizeof(isprime));
  isprime[1] = false;
  for (int i = 2; i <= m; i++) {
    if (isprime[i]) prime[++tot] = i;
    for (int j = 1; j <= tot && i * prime[j] <= m; j++) {
      isprime[i * prime[j]] = false;
      if (i % prime[j] == 0) break;
    }
  }
  for (int i = 0; i < m; i++) l[i] = 1;
  for (int i = 1; i < m; i++)
    if (isprime[i]) p[i] = 1;
  return;
}
struct Edge {
  int to, next;
} edge[N << 1];
int head[N], cnt;
void add_edge(int u, int v) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  head[u] = cnt;
  return;
}
int w[N];
int dfn[N], Index;
int siz[N];
void dfs(int u, int father) {
  dfn[u] = ++Index;
  w[Index] = a[u];
  siz[u] = 1;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == father) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  return;
}
struct Node {
  int l, r;
  int lazy;
  bitset<M> sum;
} tree[N << 2];
void push_up(int i) {
  tree[i].sum = tree[i * 2].sum | tree[i * 2 + 1].sum;
  return;
}
void build(int i, int l, int r) {
  tree[i].l = l, tree[i].r = r;
  if (l == r) {
    tree[i].sum[w[l] % m] = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(i * 2, l, mid);
  build(i * 2 + 1, mid + 1, r);
  push_up(i);
  return;
}
void add(int i, int k) {
  k %= m;
  tree[i].sum = ((tree[i].sum << k) | (tree[i].sum >> (m - k))) & l;
  tree[i].lazy = (tree[i].lazy + k) % m;
  return;
}
void push_down(int i) {
  if (!tree[i].lazy) return;
  add(i * 2, tree[i].lazy);
  add(i * 2 + 1, tree[i].lazy);
  tree[i].lazy = 0;
  return;
}
void modify(int i, int l, int r, int k) {
  if (l <= tree[i].l && tree[i].r <= r) {
    add(i, k);
    return;
  }
  push_down(i);
  if (l <= tree[i * 2].r) modify(i * 2, l, r, k);
  if (r >= tree[i * 2 + 1].l) modify(i * 2 + 1, l, r, k);
  push_up(i);
  return;
}
bitset<M> query(int i, int l, int r) {
  if (l <= tree[i].l && tree[i].r <= r) return tree[i].sum;
  push_down(i);
  if (r <= tree[i * 2].r)
    return query(i * 2, l, r);
  else if (l >= tree[i * 2 + 1].l)
    return query(i * 2 + 1, l, r);
  else
    return query(i * 2, l, r) | query(i * 2 + 1, l, r);
}
int main() {
  scanf("%d%d", &n, &m);
  init(m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add_edge(x, y);
    add_edge(y, x);
  }
  dfs(1, 0);
  build(1, 1, n);
  scanf("%d", &q);
  while (q--) {
    int op, v, x;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &v, &x);
      modify(1, dfn[v], dfn[v] + siz[v] - 1, x);
    } else if (op == 2) {
      scanf("%d", &v);
      printf("%u\n", (query(1, dfn[v], dfn[v] + siz[v] - 1) & p).count());
    }
  }
  return 0;
}