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;
template <class T, class X>
inline bool checkbit(T a, X pos) {
  T t = 1;
  return ((a & (t << pos)) > 0);
}
template <class T, class X>
inline T setbit(T a, X pos) {
  T t = 1;
  return (a | (t << pos));
}
template <class T, class X>
inline T resetbit(T a, X pos) {
  T t = 1;
  return (a & (~(t << pos)));
}
template <class T, class X>
inline T togglebit(T a, X pos) {
  T t = 1;
  return (a ^ (t << pos));
}
template <typename T>
T POW(T base, T power) {
  T ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base);
    base = (base * base);
    power >>= 1;
  }
  return ret;
}
template <typename T>
T PPOW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return ((POW(B, P / 2)) * (POW(B, P / 2)));
}
template <typename T>
T Bigmod(T base, T power, T mod) {
  T ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % mod;
    base = (base * base) % mod;
    power >>= 1;
  }
  return ret;
}
template <typename T>
T ModInverse(T number, T mod) {
  return Bigmod(number, mod - 2, mod);
}
template <typename T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (b == 0) ? a : GCD(b, a % b);
}
template <typename T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return a * (b / GCD(a, b));
}
template <typename T>
T EUCLIDE(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <typename T>
T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
double DIS(T x1, T y1, T x2, T y2) {
  return sqrt((double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
template <typename T>
T ANGLE(T x1, T y1, T x2, T y2) {
  return atan(double(y1 - y2) / double(x1 - x2));
}
template <typename T>
long long isLeft(T a, T b, T c) {
  return (c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y);
}
void P_ARR(int *ar, int a, int b) {
  if (a > b) swap(a, b);
  if (a <= b) cout << ar[a];
  for (int i = a + 1; i <= b; i++) cout << " " << ar[i];
  cout << endl;
}
template <typename T>
T In() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
bitset<1001> tree[400007];
int ar[400007];
int st[400007], ed[400007];
vector<int> adj[400007];
int id[400007];
int cl;
void push_up(int idx, int l, int r) { tree[idx] = (tree[l] | tree[r]); }
void build(int idx, int s, int e) {
  tree[idx].reset();
  if (s == e) {
    tree[idx].set(ar[id[s]]);
    return;
  }
  int mid = (s + e) >> 1, l = (idx << 1), r = (l | 1);
  build(l, s, mid);
  build(r, mid + 1, e);
  tree[idx] = (tree[l] | tree[r]);
}
int lazy[400007];
int md;
void Rotate(int idx, int v) {
  tree[idx] = ((tree[idx] << v) | (tree[idx] >> (md - v)));
}
void push_down(int idx, int l, int r) {
  Rotate(l, lazy[idx]);
  Rotate(r, lazy[idx]);
  lazy[l] = (lazy[l] + lazy[idx]) % md;
  lazy[r] = (lazy[r] + lazy[idx]) % md;
  lazy[idx] = 0;
}
void update(int idx, int s, int e, int x, int y, int v) {
  if (s == x && e == y) {
    lazy[idx] = (lazy[idx] + v) % md;
    Rotate(idx, v);
    return;
  }
  int mid = (s + e) >> 1, l = (idx << 1), r = (l | 1);
  if (lazy[idx]) push_down(idx, l, r);
  if (y <= mid)
    update(l, s, mid, x, y, v);
  else if (x > mid)
    update(r, mid + 1, e, x, y, v);
  else {
    update(l, s, mid, x, mid, v);
    update(r, mid + 1, e, mid + 1, y, v);
  }
  push_up(idx, l, r);
}
bitset<1001> ret;
void query(int idx, int s, int e, int x, int y) {
  if (s == x && e == y) {
    ret = (ret | tree[idx]);
    return;
  }
  int mid = (s + e) >> 1, l = (idx << 1), r = (l | 1);
  if (lazy[idx]) push_down(idx, l, r);
  if (y <= mid)
    query(l, s, mid, x, y);
  else if (x > mid)
    query(r, mid + 1, e, x, y);
  else {
    query(l, s, mid, x, mid);
    query(r, mid + 1, e, mid + 1, y);
    return;
  }
}
void dfs(int u, int papa) {
  st[u] = ++cl;
  id[cl] = u;
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == papa) continue;
    dfs(v, u);
  }
  ed[u] = cl;
}
bitset<1001> prime, prm;
void sieve() {
  prm.set();
  for (int i = 2; i < md; i++) {
    if (prm[i])
      for (int j = (i + i); j < md; j += i) {
        prm.reset(j);
      }
  }
  prime.reset();
  for (int i = 2; i <= md - 1; i++)
    if (prm[i]) prime.set(i);
}
int main() {
  int n;
  scanf("%d", &(n));
  ;
  scanf("%d", &(md));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(ar[i]));
    ar[i] %= md;
  }
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &(x), &(y));
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0);
  build(1, 1, n);
  sieve();
  int q;
  scanf("%d", &(q));
  ;
  for (int qq = 1; qq <= q; qq++) {
    int cmd;
    scanf("%d", &(cmd));
    ;
    if (cmd == 1) {
      int x, v;
      scanf("%d%d", &(x), &(v));
      v %= md;
      update(1, 1, n, st[x], ed[x], v);
    } else {
      int x;
      scanf("%d", &(x));
      ;
      ret.reset();
      query(1, 1, n, st[x], ed[x]);
      int cnt = (ret & prime).count();
      printf("%d\n", cnt);
    }
  }
  return 0;
}