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;
bitset<2005> a[100005 << 2], one, zero, choose, ans;
int End[100005 << 1], Next[100005 << 1], Go[100005 << 1], cnt;
int add[100005 << 2], flag[100005], L[100005], R[100005], init[100005],
    w[100005];
int i, j, n, tot, P, z, S, T, k, Q, opt, x, y, ql, qr;
void Link(int u, int v) {
  Go[++cnt] = v;
  Next[cnt] = End[u];
  End[u] = cnt;
}
void DFS(int x, int Fa) {
  init[L[x] = ++tot] = w[x];
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != Fa) DFS(y, x);
  R[x] = tot;
}
void renew(int x, int z) {
  add[x] += z;
  if (add[x] >= P) add[x] -= P;
  a[x] = a[x] << z;
  a[x] |= a[x] >> P;
  a[x] &= one;
}
void down(int x) {
  if (!add[x]) return;
  renew(x << 1, add[x]);
  renew(x << 1 | 1, add[x]);
  add[x] = 0;
}
void build(int x, int l, int r) {
  if (l == r) {
    a[x][init[l]] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  a[x] = a[x << 1] | a[x << 1 | 1];
}
void Update(int x, int l, int r) {
  if (ql <= l && r <= qr) {
    renew(x, z);
    return;
  }
  int mid = (l + r) >> 1;
  down(x);
  if (ql <= mid) Update(x << 1, l, mid);
  if (qr > mid) Update(x << 1 | 1, mid + 1, r);
  a[x] = a[x << 1] | a[x << 1 | 1];
}
void Query(int x, int l, int r) {
  if (ql <= l && r <= qr) {
    ans |= a[x];
    return;
  }
  int mid = (l + r) >> 1;
  down(x);
  if (ql <= mid) Query(x << 1, l, mid);
  if (qr > mid) Query(x << 1 | 1, mid + 1, r);
}
int main() {
  flag[0] = flag[1] = 1;
  for (i = 2; i <= 1000; i++)
    if (!flag[i])
      for (j = i + i; j <= 1000; j += i) flag[j] = 1;
  scanf("%d%d", &n, &P);
  for (i = 0; i < P; i++) one[i] = 1;
  for (i = 0; i < P; i++)
    if (!flag[i]) choose[i] = 1;
  for (i = 1; i <= n; i++) scanf("%d", &w[i]), w[i] %= P;
  for (i = 1; i < n; i++) scanf("%d%d", &x, &y), Link(x, y), Link(y, x);
  DFS(1, 0);
  build(1, 1, n);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &opt, &x);
    if (opt == 2) {
      ans = zero;
      ql = L[x], qr = R[x];
      Query(1, 1, n);
      printf("%d\n", (ans & choose).count());
    } else
      scanf("%d", &z), z %= P, ql = L[x], qr = R[x], Update(1, 1, n);
  }
}