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 <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
const int N = (int)1e5 + 5;
int n, m, timer, tin[N], tout[N], a[N], aa[N], lazy[1 << 18];
bitset<1000> p, tree[1 << 18], emp;
vector<int> g[N];
void dfs_prep(int u, int p) {
  tin[u] = ++timer, aa[timer] = a[u];
  for (int i = (0); i < (((int)g[u].size())); ++i) {
    int v = g[u][i];
    if (v == p) continue;
    dfs_prep(v, u);
  }
  tout[u] = timer;
}
void init() {
  dfs_prep(1, 0);
  for (int i = (2); i < (m); ++i) p[i] = 1;
  for (int i = (2); i < (m); ++i)
    if (p[i]) {
      for (int j = i + i; j < m; j += i) p[j] = 0;
    }
}
void build_tree(int k, int l, int r) {
  if (l > r) return;
  if (l == r) {
    tree[k][aa[l] % m] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build_tree(k << 1, l, mid);
  build_tree(k << 1 | 1, mid + 1, r);
  tree[k] = (tree[k << 1] | tree[k << 1 | 1]);
}
inline void lazy_update(int k, int l, int r) {
  if (!lazy[k]) return;
  int val = lazy[k];
  lazy[k] = 0;
  tree[k] = ((tree[k] >> (m - val)) | (tree[k] << val));
  if (l != r) {
    lazy[k << 1] = (lazy[k << 1] + val) % m;
    lazy[k << 1 | 1] = (lazy[k << 1 | 1] + val) % m;
  }
}
void update(int k, int l, int r, int L, int R, int val) {
  lazy_update(k, l, r);
  if (l > r || l > R || r < L) return;
  if (L <= l && r <= R) {
    lazy[k] = (lazy[k] + val) % m;
    lazy_update(k, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update(k << 1, l, mid, L, R, val);
  update(k << 1 | 1, mid + 1, r, L, R, val);
  tree[k] = (tree[k << 1] | tree[k << 1 | 1]);
}
bitset<1000> query(int k, int l, int r, int L, int R) {
  if (l > r || l > R || r < L) return emp;
  lazy_update(k, l, r);
  if (L <= l && r <= R) return tree[k];
  int mid = (l + r) >> 1;
  return query(k << 1, l, mid, L, R) | query(k << 1 | 1, mid + 1, r, L, R);
}
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);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  init();
  build_tree(1, 1, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, v, x;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      scanf("%d", &x);
      update(1, 1, n, tin[v], tout[v], x % m);
    } else
      printf("%d\n", (query(1, 1, n, tin[v], tout[v]) & p).count());
  }
  return 0;
}