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 long long MN = 1e5 + 7;
const long long MK = 1007;
long long n, m, lv[MN], rv[MN], w[MN], lazy[MN << 2], mark[MN];
bitset<MK> a[MN << 2], p;
vector<long long> g[MN], to;
void sh(long long u, long long x) { a[u] = (a[u] >> (m - x)) | (a[u] << x); }
void push(long long l, long long r, long long u) {
  lazy[u] %= m;
  if (l == r) {
    lazy[u] = 0;
    return;
  }
  sh((u << 1), lazy[u]);
  sh(((u << 1) | 1), lazy[u]);
  lazy[(u << 1)] = (lazy[(u << 1)] + lazy[u]) % m;
  lazy[((u << 1) | 1)] = (lazy[((u << 1) | 1)] + lazy[u]) % m;
  lazy[u] = 0;
}
void upd(long long l, long long r, long long u, long long x, long long y,
         long long w) {
  if (x > y) return;
  if (l == x && r == y) {
    sh(u, w);
    lazy[u] = (lazy[u] + w) % m;
    return;
  }
  push(l, r, u);
  upd(l, ((l + r) >> 1), (u << 1), x, min(y, ((l + r) >> 1)), w);
  upd(((l + r) >> 1) + 1, r, ((u << 1) | 1), max(x, ((l + r) >> 1) + 1), y, w);
  a[u] = a[(u << 1)] | a[((u << 1) | 1)];
}
bitset<MK> ask(long long l, long long r, long long u, long long x,
               long long y) {
  if (x > y) return bitset<MK>();
  if (l == x && r == y) {
    return a[u];
  }
  push(l, r, u);
  return ask(l, ((l + r) >> 1), (u << 1), x, min(y, ((l + r) >> 1))) |
         ask(((l + r) >> 1) + 1, r, ((u << 1) | 1), max(x, ((l + r) >> 1) + 1),
             y);
}
void dfs(long long now) {
  lv[now] = to.size();
  mark[now] = 1;
  for (long long i : g[now])
    if (!mark[i]) dfs(i);
  rv[now] = to.size();
  to.push_back(now);
}
void build(long long l, long long r, long long u) {
  if (l == r) {
    a[u].set(w[to[l]]);
    return;
  }
  build(l, ((l + r) >> 1), (u << 1));
  build(((l + r) >> 1) + 1, r, ((u << 1) | 1));
  a[u] = a[(u << 1)] | a[((u << 1) | 1)];
}
signed main() {
  cin >> n >> m;
  for (long long i = 2; i < m; i++) p.set(i);
  for (long long i = 2; i < m; i++) {
    if (!p[i]) continue;
    long long x = i * i;
    while (x < m) {
      p[x] = 0;
      x += i;
    }
  }
  for (long long i = 1; i <= n; i++) {
    cin >> w[i];
    w[i] %= m;
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  build(0, n - 1, 1);
  long long f;
  cin >> f;
  while (f--) {
    long long t, v;
    cin >> t >> v;
    if (t == 1) {
      long long x;
      cin >> x;
      x %= m;
      upd(0, n - 1, 1, lv[v], rv[v], x);
    } else {
      cout << (ask(0, n - 1, 1, lv[v], rv[v]) & p).count() << endl;
    }
  }
}