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 X, class Y>
void minimize(X &x, const Y &y) {
  if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
  if (x < y) x = y;
}
bool notPrime[1010];
int a[100100];
vector<int> adj[100100], prime;
int sta[100100], fin[100100], cnt, n, mod, q;
struct BitSet {
  static const int SIZE = 1024;
  unsigned int val[32];
  int root;
  BitSet() {
    root = 0;
    memset(val, 0, sizeof val);
  }
  bool get(int x) const {
    x = (x + root) % mod;
    return ((((val[x >> 5]) >> (x & 31)) & 1));
  }
  unsigned int getBlock(int L, int R) const {
    if (L > R) return (0);
    int oldL = L;
    int oldR = R;
    L = (L + root) % mod;
    R = (R + root) % mod;
    if (L <= R) {
      int id = L >> 5;
      unsigned long long tmp = val[id] | ((1ULL * val[id + 1]) << 32);
      tmp = tmp >> (L & 31);
      return (tmp & ((1ULL << (R - L + 1)) - 1));
    } else {
      int ___left = mod - L;
      int ___right = R + 1;
      return (getBlock(oldL, oldL + ___left - 1) |
              (1ULL * getBlock(oldR - ___right + 1, oldR) << ___left));
    }
  }
  BitSet merge(const BitSet &x) const {
    BitSet res;
    for (int i = 0, _n = (32); i < _n; i = i + 1)
      res.val[i] = getBlock(32 * i, min(32 * i + 31, mod - 1)) |
                   x.getBlock(32 * i, min(32 * i + 31, mod - 1));
    return (res);
  }
  void rotate(int x) { root = ((root - x) % mod + mod) % mod; }
};
BitSet initBitSet(void) {
  BitSet res;
  res.val[0] = 1;
  return (res);
}
class SegmentTree {
 private:
  vector<BitSet> tree;
  vector<int> lazy;
  int n;
  void pushDown(int i) {
    if (lazy[i] == 0) return;
    for (int j = (2 * i), _b = (2 * i + 1); j <= _b; j = j + 1) {
      tree[j].rotate(lazy[i]);
      lazy[j] = (lazy[j] + lazy[i]) % mod;
    }
    lazy[i] = 0;
  }
  void update(int i, int l, int r, int u, int v, int c) {
    if (l > v || r < u || l > r || v < u) return;
    if (u <= l && r <= v) {
      tree[i].rotate(c);
      lazy[i] = (lazy[i] + c) % mod;
      return;
    }
    pushDown(i);
    int m = (l + r) >> 1;
    update(2 * i, l, m, u, v, c);
    update(2 * i + 1, m + 1, r, u, v, c);
    tree[i] = tree[2 * i].merge(tree[2 * i + 1]);
  }
  BitSet get(int i, int l, int r, int u, int v) {
    if (l > v || r < u || l > r || v < u) return (BitSet());
    if (u <= l && r <= v) return (tree[i]);
    pushDown(i);
    int m = (l + r) >> 1;
    BitSet L = get(2 * i, l, m, u, v);
    BitSet R = get(2 * i + 1, m + 1, r, u, v);
    return (L.merge(R));
  }

 public:
  SegmentTree() { n = 0; }
  SegmentTree(int n) {
    this->n = n;
    tree.assign(4 * n + 7, initBitSet());
    lazy.assign(4 * n + 7, 0);
  }
  void update(int l, int r, int c) { update(1, 1, n, l, r, c % mod); }
  BitSet get(int l, int r) { return (get(1, 1, n, l, r)); }
};
void loadTree(void) {
  scanf("%d%d", &n, &mod);
  for (int i = (1), _b = (n); i <= _b; i = i + 1) scanf("%d", &a[i]);
  for (int love = 0, _n = (n - 1); love < _n; love = love + 1) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
void dfs(int u, int p) {
  sta[u] = ++cnt;
  for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end();
       it++)
    if (*it != p) dfs(*it, u);
  fin[u] = cnt;
}
void prepare(void) {
  for (int i = 0, _n = (2); i < _n; i = i + 1) notPrime[i] = true;
  for (int i = (2), _b = (mod - 1); i <= _b; i = i + 1)
    if (!notPrime[i]) {
      prime.push_back(i);
      for (int j = 2 * i; j < mod; j = j + i) notPrime[j] = true;
    }
  dfs(1, -1);
}
void process(void) {
  SegmentTree myit(n);
  for (int i = (1), _b = (n); i <= _b; i = i + 1)
    myit.update(sta[i], sta[i], a[i]);
  scanf("%d", &q);
  for (int love = 0, _n = (q); love < _n; love = love + 1) {
    int t, v;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      int x;
      scanf("%d", &x);
      myit.update(sta[v], fin[v], x);
    } else {
      BitSet tmp = myit.get(sta[v], fin[v]);
      int res = 0;
      for (__typeof((prime).begin()) it = (prime).begin(); it != (prime).end();
           it++)
        if (tmp.get(*it)) res++;
      printf("%d\n", res);
    }
  }
}
int main(void) {
  loadTree();
  prepare();
  process();
  return 0;
}