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;
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 412345;
int n, m;
vector<int> v[N];
vector<int> w;
int a[N];
int tin[N], tout[N], tim;
void dfs(int x, int f) {
  w.push_back(x);
  tin[x] = ++tim;
  for (int i = 0; i < v[x].size(); i++) {
    int to = v[x][i];
    if (to != f) {
      dfs(to, x);
    }
  }
  tout[x] = tim;
}
const int M = 1000;
bitset<M> d[N];
int shift[N];
bitset<M> all;
bitset<M> res;
bitset<M> prim;
void built(int l, int r, int id) {
  if (l == r) {
    d[id].set(a[w[l]]);
    return;
  }
  int y = (l + r) >> 1;
  built(l, y, id + id);
  built(y + 1, r, id + id + 1);
  d[id] = d[id + id] | d[id + id + 1];
}
void apply(bitset<M> &b, int x) { b = (((b << x) & all) | (b >> (m - x))); }
void push(int x) {
  if (shift[x]) {
    shift[x + x] += shift[x];
    if (shift[x + x] >= m) shift[x + x] -= m;
    apply(d[x + x], shift[x]);
    shift[x + x + 1] += shift[x];
    if (shift[x + x + 1] >= m) shift[x + x + 1] -= m;
    apply(d[x + x + 1], shift[x]);
    shift[x] = 0;
  }
}
void upd(int l, int r, int id, int ll, int rr, int x) {
  if (ll <= l && r <= rr) {
    apply(d[id], x);
    shift[id] += x;
    if (shift[id] >= m) shift[id] -= m;
    return;
  }
  push(id);
  int y = (l + r) >> 1;
  if (ll <= y) upd(l, y, id + id, ll, rr, x);
  if (rr > y) upd(y + 1, r, id + id + 1, ll, rr, x);
  d[id] = (d[id + id] | d[id + id + 1]);
}
void getlr(int l, int r, int id, int ll, int rr) {
  if (ll <= l && r <= rr) {
    res |= d[id];
    return;
  }
  push(id);
  int y = (l + r) >> 1;
  if (ll <= y) getlr(l, y, id + id, ll, rr);
  if (rr > y) getlr(y + 1, r, id + id + 1, ll, rr);
  d[id] = (d[id + id] | d[id + id + 1]);
}
int main() {
  int i, j, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) a[i] = read(), a[i] %= m;
  for (i = 1; i < n; i++) {
    x = read();
    y = read();
    v[x].push_back(y);
    v[y].push_back(x);
  }
  w.push_back(0);
  dfs(1, 1);
  for (i = 2; i < m; i++) {
    bool ok = 1;
    for (j = 2; j * j <= i; j++)
      if (i % j == 0) ok = 0;
    if (ok) prim.set(i);
  }
  for (i = 0; i < m; i++) all.set(i);
  int t;
  built(1, n, 1);
  t = read();
  for (i = 1; i <= t; i++) {
    y = read();
    x = read();
    if (y == 1) {
      int sh = read();
      sh %= m;
      if (sh == 0) continue;
      upd(1, n, 1, tin[x], tout[x], sh);
    } else {
      res.reset();
      getlr(1, n, 1, tin[x], tout[x]);
      int ans = (res & prim).count();
      printf("%d\n", ans);
    }
  }
}