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 = 1e5 + 10;
int n, m, a[maxn], cha[maxn], tin[maxn], tout[maxn];
int Eu[maxn], ptr[maxn];
vector<int> ke[maxn];
vector<int> pr;
bitset<1000> t[maxn * 4], g[1001];
int lz[maxn * 4];
void shift(bitset<1000>& bs, int x) {
  int c = m - x;
  bs = (bs >> c) | (bs << x);
}
void push_down(int k, int l, int r) {
  int x = lz[k];
  if (x == 0) return;
  shift(t[k], x);
  lz[k] = 0;
  if (l != r) {
    lz[k * 2] = (lz[k * 2] + x) % m;
    lz[k * 2 + 1] = (lz[k * 2 + 1] + x) % m;
  }
}
void build(int k, int l, int r) {
  if (l == r) return void(t[k] = bitset<1000>().set(a[Eu[l]] % m));
  build(k * 2, l, ((l + r) >> 1));
  build(k * 2 + 1, ((l + r) >> 1) + 1, r);
  t[k] = t[k * 2] | t[k * 2 + 1];
}
void update(int k, int l, int r, int i, int j, int x) {
  push_down(k, l, r);
  if (j < l || i > r) return;
  if (i <= l && r <= j) {
    lz[k] = (lz[k] + x) % m;
    return void(push_down(k, l, r));
  }
  update(k * 2, l, ((l + r) >> 1), i, j, x);
  update(k * 2 + 1, ((l + r) >> 1) + 1, r, i, j, x);
  t[k] = t[k * 2] | t[k * 2 + 1];
}
bitset<1000> get(int k, int l, int r, int i, int j) {
  push_down(k, l, r);
  if (j < l || i > r) return bitset<1000>();
  if (i <= l && r <= j) return t[k];
  bitset<1000> ret = get(k * 2, l, ((l + r) >> 1), i, j) |
                     get(k * 2 + 1, ((l + r) >> 1) + 1, r, i, j);
  t[k] = t[k * 2] | t[k * 2 + 1];
  return ret;
}
void dfs() {
  int timer = 0;
  vector<int> s;
  cha[1] = -1;
  s.push_back(1);
  tin[1] = ++timer;
  Eu[1] = 1;
  while (!s.empty()) {
    int u = s.back(), &i = ptr[u];
    if (i == ke[u].size()) {
      tout[u] = timer;
      s.pop_back();
      continue;
    }
    while (i < ke[u].size()) {
      int v = ke[u][i++];
      if (cha[v]) continue;
      cha[v] = u;
      s.push_back(v);
      tin[v] = ++timer;
      Eu[timer] = v;
      break;
    }
  }
}
bool is_prime(int n) {
  if (n <= 1) return 0;
  if (n == 2) return 1;
  if (n % 2 == 0) return 0;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return 0;
  return 1;
}
void solve() {
  int q;
  scanf("%d", &q);
  for (; q; --q) {
    int k, v, x;
    scanf("%d", &k);
    if (k == 1) {
      scanf("%d%d", &v, &x);
      update(1, 1, n, tin[v], tout[v], x);
    } else {
      scanf("%d", &v);
      int ans = 0;
      bitset<1000> f = get(1, 1, n, tin[v], tout[v]);
      for (int i = 0; i < pr.size(); ++i)
        if (f[pr[i]]) {
          ++ans;
        }
      printf("%d\n", ans);
    }
  }
}
void test() {
  bitset<1000> bs;
  m = 1000;
  for (int i = 5; i < 10; ++i) bs.set(i);
  bs.set(0);
  cout << bs << "\n";
  shift(bs, 5);
  cout << bs << "\n";
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    ke[u].push_back(v);
    ke[v].push_back(u);
  }
  for (int i = 1; i < m; ++i)
    if (is_prime(i)) pr.push_back(i);
  dfs();
  build(1, 1, n);
  solve();
}