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 n, m, i, x, y, q, tp, v, Ans, j;
vector<int> g[1400005];
bitset<1000> t[1400005];
int tag[1400005];
int ps[1400005];
int sz[1400005];
bitset<1000> X;
int a[1400005];
int ord[1400005];
bool vis[1400005];
int P[2222];
void dfs(int x, int p) {
  ord[++q] = x;
  ps[x] = q, sz[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] == p) continue;
    dfs(g[x][i], x);
    sz[x] += sz[g[x][i]];
  }
}
void Build(int x, int l, int r) {
  if (l == r)
    t[x].set(a[ord[l]] % m);
  else {
    int mid = (l + r) >> 1;
    Build(x + x, l, mid);
    Build(x + x + 1, mid + 1, r);
    t[x] = t[x + x] | t[x + x + 1];
  }
}
void Rot(int x, int sq) { t[x] = (t[x] << sq) | (t[x] >> (m - sq)); }
void Push(int x) {
  tag[x] %= m;
  if (tag[x] != 0) {
    Rot(x + x, tag[x]);
    Rot(x + x + 1, tag[x]);
    tag[x + x] += tag[x];
    tag[x + x + 1] += tag[x];
    tag[x] = 0;
  }
}
void Rotate(int x, int l, int r, int ll, int rr, int shi) {
  Push(x), Push(x + x), Push(x + x + 1);
  if (l == ll && r == rr) {
    Rot(x, shi);
    tag[x] += shi;
    tag[x] %= m;
    Push(x), Push(x + x), Push(x + x + 1);
  } else {
    Push(x), Push(x + x), Push(x + x + 1);
    int mid = (l + r) >> 1;
    if (rr <= mid)
      Rotate(x + x, l, mid, ll, rr, shi);
    else if (ll > mid)
      Rotate(x + x + 1, mid + 1, r, ll, rr, shi);
    else {
      Rotate(x + x, l, mid, ll, mid, shi);
      Rotate(x + x + 1, mid + 1, r, mid + 1, rr, shi);
    }
    Push(x), Push(x + x), Push(x + x + 1);
    t[x] = t[x + x] | t[x + x + 1];
    Push(x), Push(x + x), Push(x + x + 1);
  }
  Push(x), Push(x + x), Push(x + x + 1);
}
bitset<1000> Query(int x, int l, int r, int ll, int rr) {
  Push(x), Push(x + x), Push(x + x + 1);
  if (l == ll && r == rr)
    return t[x];
  else {
    Push(x), Push(x + x), Push(x + x + 1);
    int mid = (l + r) >> 1;
    if (rr <= mid)
      return Query(x + x, l, mid, ll, rr);
    else if (ll > mid)
      return Query(x + x + 1, mid + 1, r, ll, rr);
    else {
      bitset<1000> A = Query(x + x, l, mid, ll, mid);
      bitset<1000> B = Query(x + x + 1, mid + 1, r, mid + 1, rr);
      return A | B;
    }
  }
  Push(x), Push(x + x), Push(x + x + 1);
}
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++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 2; i < m; i++)
    if (!vis[i]) {
      P[++P[0]] = i;
      for (int j = 2 * i; j < m; j += i) vis[j] = 1;
    }
  dfs(1, -1);
  Build(1, 1, n);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d", &v, &x);
      Rotate(1, 1, n, ps[v], ps[v] + sz[v] - 1, x % m);
    } else {
      scanf("%d", &v);
      Ans = 0;
      bitset<1000> A = Query(1, 1, n, ps[v], ps[v] + sz[v] - 1);
      for (int j = 1; j <= P[0]; j++) Ans += A.test(P[j]);
      printf("%d\n", Ans);
    }
  }
  return 0;
}