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 = 100100, M = 1010, D = 32;
int i, j, k, n, m, q, o, x, y, ch, Pn, En;
int a[N], h[N], l[N], r[N], p[N], Cnt[65536];
struct Bitset {
  unsigned int a[D];
  int count() {
    int i, cnt = 0;
    for (i = 0; i < D; i++) cnt += Cnt[a[i] >> 16] + Cnt[a[i] & 65535];
    return cnt;
  }
  void clear() { memset(a, 0, sizeof a); }
  void up(const Bitset &x, const Bitset &y) {
    for (int i = 0; i < D; i++) a[i] = x.a[i] | y.a[i];
  }
  void operator|=(const int &n) { a[n >> 5] |= 1u << (n & 31); }
  Bitset operator|(const Bitset &n) {
    Bitset t;
    for (int i = 0; i < D; i++) t.a[i] = a[i] | n.a[i];
    return t;
  }
  void operator|=(const Bitset &n) {
    for (int i = 0; i < D; i++) a[i] |= n.a[i];
  }
  Bitset operator&(const Bitset &n) {
    Bitset t;
    for (int i = 0; i < D; i++) t.a[i] = a[i] & n.a[i];
    return t;
  }
  void operator+=(int n) {
    Bitset t;
    t = *this;
    memset(a, 0, sizeof a);
    for (int x = n >> 5, y = n & 31, z = 32 - y, i = 0; x + i < D; i++) {
      a[x + i] |= t.a[i] << y;
      if (y && x + i + 1 < D) a[x + i + 1] |= t.a[i] >> z;
    }
    n = m - n;
    for (int x = n >> 5, y = n & 31, z = 32 - y, i = 0; x + i < D; i++) {
      a[i] |= t.a[x + i] >> y;
      if (y && i - 1 >= 0) a[i - 1] |= t.a[x + i] << z;
    }
  }
} pr, Ans;
struct tree {
  int ad;
  Bitset Bit;
} T[N << 2];
struct edge {
  int s, n;
} E[N << 1];
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
void W(int x) {
  if (x >= 10) W(x / 10);
  putchar(x % 10 + '0');
}
void pre(int m) {
  for (int i = 2, j; i < m; i++) {
    for (j = 2; j * j <= i; j++)
      if (i % j == 0) break;
    if (j * j > i) pr |= i;
  }
  for (int i = 0; i < 65536; i++) {
    int j = i;
    while (j) Cnt[i] += j & 1, j >>= 1;
  }
}
void E_add(int x, int y) {
  E[++En].s = y;
  E[En].n = h[x];
  h[x] = En;
  E[++En].s = x;
  E[En].n = h[y];
  h[y] = En;
}
void dfs(int x, int F) {
  l[x] = ++Pn;
  p[Pn] = x;
  for (int k = h[x]; k; k = E[k].n)
    if (E[k].s != F) dfs(E[k].s, x);
  r[x] = Pn;
}
void down(int k) {
  if (T[k].ad) {
    T[k << 1].ad = (T[k << 1].ad + T[k].ad) % m;
    T[k << 1 | 1].ad = (T[k << 1 | 1].ad + T[k].ad) % m;
    T[k << 1].Bit += T[k].ad;
    T[k << 1 | 1].Bit += T[k].ad;
    T[k].ad = 0;
  }
}
void T_build(int L, int R, int k) {
  if (L == R) {
    T[k].ad = 0;
    T[k].Bit |= a[p[L]];
    return;
  }
  int mid = (L + R) >> 1;
  T_build(L, mid, k << 1);
  T_build(mid + 1, R, k << 1 | 1);
  T[k].Bit.up(T[k << 1].Bit, T[k << 1 | 1].Bit);
}
void T_add(int L, int R, int l, int r, int ad, int k) {
  if (L == l && R == r) {
    T[k].ad = (T[k].ad + ad) % m;
    T[k].Bit += ad;
    return;
  }
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid)
    T_add(L, mid, l, r, ad, k << 1);
  else {
    if (l > mid)
      T_add(mid + 1, R, l, r, ad, k << 1 | 1);
    else
      T_add(L, mid, l, mid, ad, k << 1),
          T_add(mid + 1, R, mid + 1, r, ad, k << 1 | 1);
  }
  T[k].Bit.up(T[k << 1].Bit, T[k << 1 | 1].Bit);
}
void T_query(int L, int R, int l, int r, int k) {
  if (L == l && R == r) {
    Ans |= T[k].Bit;
    return;
  }
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid)
    T_query(L, mid, l, r, k << 1);
  else {
    if (l > mid)
      T_query(mid + 1, R, l, r, k << 1 | 1);
    else
      T_query(L, mid, l, mid, k << 1),
          T_query(mid + 1, R, mid + 1, r, k << 1 | 1);
  }
}
int main() {
  R(n);
  R(m);
  pre(m);
  for (i = 1; i <= n; i++) R(a[i]), a[i] %= m;
  for (i = 1; i < n; i++) R(x), R(y), E_add(x, y);
  dfs(1, 0);
  T_build(1, n, 1);
  R(q);
  for (i = 1; i <= q; i++) {
    R(o);
    if (o == 1)
      R(x), R(y), T_add(1, n, l[x], r[x], y % m, 1);
    else {
      Ans.clear();
      R(x);
      T_query(1, n, l[x], r[x], 1);
      W((Ans & pr).count()), puts("");
    }
  }
}