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 MaxN = 222222;
int v[MaxN], __next__[MaxN], h[MaxN], tot;
void add(int b, int e) {
  v[++tot] = e;
  __next__[tot] = h[b];
  h[b] = tot;
  v[++tot] = b;
  __next__[tot] = h[e];
  h[e] = tot;
}
int id = 0;
int vis[MaxN], L[MaxN], R[MaxN], seq[MaxN], A[MaxN];
void dfs(int x) {
  vis[x] = true;
  seq[L[x] = ++id] = x;
  for (int z = h[x]; z; z = __next__[z])
    if (!vis[v[z]]) {
      dfs(v[z]);
    }
  R[x] = id;
}
const int B = 62;
int BLK = 0;
int MOD;
struct TData {
  long long Mask[22];
  TData() {}
  void clear() { memset(Mask, 0, sizeof Mask); }
  void set(int x, long long val) {
    long long &S = Mask[x / B];
    x %= B;
    if (S >> x & 1) S -= 1LL << x;
    S |= val << x;
  }
  int get(int x) { return Mask[x / B] >> (x % B) & 1; }
  TData operator+(const TData &b) const {
    TData ret;
    memcpy(ret.Mask, Mask, sizeof Mask);
    for (int i = 0; i <= BLK; ++i) ret.Mask[i] |= b.Mask[i];
    return ret;
  }
  TData move(int offset) {
    offset %= MOD;
    TData ret;
    ret.clear();
    for (int i = 0; i < MOD;) {
      int t = (i + offset) % MOD;
      int nxt_i = min(MOD - 1, i / B * B + B - 1);
      int nxt_t = min(MOD - 1, t / B * B + B - 1);
      int inc = min(nxt_i - i, nxt_t - t) + 1;
      ret.Mask[t / B] |= (Mask[i / B] >> i % B & ((1LL << inc) - 1)) << (t % B);
      i += inc;
    }
    return ret;
  }
};
struct SegTreeNode {
  int l, r, offset;
  TData info;
  SegTreeNode() {}
  void init(int _l, int _r, int _val) {
    l = _l, r = _r;
    info.clear();
    info.set(_val % MOD, 1);
    offset = 0;
  }
  void make_add(int c) {
    (offset += c) %= MOD;
    info = info.move(c % MOD);
  }
} T[MaxN * 2];
struct SegmentTree {
  void push(int t) {
    if (T[t].offset) {
      if (T[t].l == T[t].r) return;
      T[t + t].make_add(T[t].offset);
      T[t + t + 1].make_add(T[t].offset);
      T[t].offset = 0;
    }
  }
  void update(int t) {
    if (T[t].l == T[t].r) return;
    T[t].info = T[t + t].info + T[t + t + 1].info;
  }
  void modify(int t, int l, int r, int val) {
    push(t);
    if (l <= T[t].l && T[t].r <= r) {
      T[t].make_add(val);
      return;
    }
    int mid = (T[t].l + T[t].r) >> 1;
    if (l <= mid) modify(t + t, l, r, val);
    if (r > mid) modify(t + t + 1, l, r, val);
    update(t);
  }
  TData ask(int t, int l, int r) {
    push(t);
    if (l <= T[t].l && T[t].r <= r) {
      return T[t].info;
    }
    int mid = (T[t].l + T[t].r) >> 1;
    TData ret;
    ret.clear();
    if (l <= mid) ret = ret + ask(t + t, l, r);
    if (r > mid) ret = ret + ask(t + t + 1, l, r);
    update(t);
    return ret;
  }
  void build(int t, int l, int r, int *seq) {
    T[t].init(l, r, A[seq[l]]);
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(t + t, l, mid, seq);
    build(t + t + 1, mid + 1, r, seq);
    update(t);
  }
} Tab;
int arr[MaxN], appear[1111];
int n, Q;
int main() {
  cin >> n >> MOD;
  vector<int> primes;
  for (int i = 2; i <= MOD - 1; ++i) {
    bool valid = true;
    for (int j = 2; j <= i - 1; ++j)
      if (i % j == 0) valid = false;
    if (valid) primes.push_back(i);
  }
  BLK = (MOD + B - 1) / B;
  for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
  for (int i = 1; i <= n - 1; ++i) {
    int b, e;
    scanf("%d%d", &b, &e);
    add(b, e);
  }
  dfs(1);
  Tab.build(1, 1, n, seq);
  for (int i = 1; i <= n; ++i) arr[i] = A[seq[i]] % MOD;
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    int op, v, x;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &v, &x);
      Tab.modify(1, L[v], R[v], x);
    }
    if (op == 2) {
      scanf("%d", &v);
      TData ans = Tab.ask(1, L[v], R[v]);
      int num = 0;
      for (auto cand : primes)
        if (ans.get(cand) == 1) ++num;
      printf("%d\n", num);
    }
  }
  return 0;
}