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>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
mt19937 ggen;
const int MAXN = 100005;
const int MAXM = 1000;
int m, n, k;
bitset<MAXM> full, primes;
int lp[MAXM];
vector<int> pr;
vector<vector<int> > g;
int a[MAXN];
int tin[MAXN], tout[MAXN], timer;
int order[MAXN];
void sieve() {
  for (int i = 2; i < m; i++) {
    if (!lp[i]) {
      pr.push_back(i);
    }
    for (int j = 0; j < pr.size(); j++) {
      int mul = pr[j] * i;
      if (mul >= m) {
        break;
      }
      lp[mul] = pr[j];
    }
  }
}
void dfs(int v, int p) {
  tin[v] = tout[v] = ++timer;
  order[timer] = v;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) {
      continue;
    }
    dfs(to, v);
    tout[v] = tout[to];
  }
}
struct node {
  bitset<MAXM> b;
  int shift;
};
node tree[MAXN << 2];
inline bitset<MAXM> cycle_shift(bitset<MAXM> b, int d) {
  return ((b << d) | (b >> (m - d))) & full;
}
inline bitset<MAXM> combine(bitset<MAXM> b1, bitset<MAXM> b2) {
  return b1 | b2;
}
inline void push(int v, int tl, int tr) {
  if (tl < tr && tree[v].shift) {
    tree[v << 1].shift += tree[v].shift;
    tree[v << 1].shift %= m;
    tree[v << 1].b = cycle_shift(tree[v << 1].b, tree[v].shift);
    tree[(v << 1) + 1].shift += tree[v].shift;
    tree[(v << 1) + 1].shift %= m;
    tree[(v << 1) + 1].b = cycle_shift(tree[(v << 1) + 1].b, tree[v].shift);
    tree[v].shift = 0;
  }
}
bitset<MAXM> get_val(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    return bitset<MAXM>();
  }
  if (tl == l && tr == r) {
    return tree[v].b;
  }
  push(v, tl, tr);
  int tm = (tl + tr) >> 1;
  return combine(get_val(v << 1, tl, tm, l, min(tm, r)),
                 get_val((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
}
void update(int v, int tl, int tr, int l, int r, int d) {
  if (l > r) {
    return;
  }
  if (tl == l && tr == r) {
    tree[v].b = cycle_shift(tree[v].b, d);
    tree[v].shift += d;
    tree[v].shift %= m;
    return;
  }
  push(v, tl, tr);
  int tm = (tl + tr) >> 1;
  update(v << 1, tl, tm, l, min(tm, r), d);
  update((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r, d);
  tree[v].b = combine(tree[v << 1].b, tree[(v << 1) + 1].b);
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    tree[v].b.set(a[order[tl]] % m);
    return;
  }
  int tm = (tl + tr) >> 1;
  build(v << 1, tl, tm);
  build((v << 1) + 1, tm + 1, tr);
  tree[v].b = combine(tree[v << 1].b, tree[(v << 1) + 1].b);
}
void solve() {
  scanf("%d%d", &n, &m);
  g.resize(n + 1);
  for (int i = 0; i < m; i++) {
    full.set(i);
  }
  sieve();
  for (int i = 0; i < pr.size(); i++) {
    primes.set(pr[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    g[v1].push_back(v2);
    g[v2].push_back(v1);
  }
  dfs(1, 0);
  build(1, 1, n);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int v, d;
      scanf("%d%d", &v, &d);
      d %= m;
      update(1, 1, n, tin[v], tout[v], d);
    } else {
      int v;
      scanf("%d", &v);
      bitset<MAXM> b = get_val(1, 1, n, tin[v], tout[v]) & primes;
      printf("%d\n", b.count());
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  ggen = mt19937(13);
  solve();
  return 0;
}