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 double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;
vector<int> rb[maxn];
bitset<1000> deo[4 * maxn], all;
int mv[4 * maxn];
int a[maxn], b[maxn], sz;
int lf[maxn], rg[maxn];
bool pm[maxn], rw[1000];
int m;
void build(int v = 0, int tl = 0, int tr = maxn - 1) {
  if (tl == tr) {
    deo[v][a[b[tl]]] = 1;
    return;
  }
  int tm = (tl + tr) >> 1;
  build(v * 2 + 1, tl, tm);
  build(v * 2 + 2, tm + 1, tr);
  deo[v] = (deo[v * 2 + 1] | deo[v * 2 + 2]);
}
void push(int v, int tl, int tr) {
  if (!mv[v]) return;
  deo[v] = (((deo[v] << mv[v]) | (deo[v] >> (m - mv[v]))) & all);
  if (tl == tr) {
    mv[v] = 0;
    return;
  }
  mv[v * 2 + 1] += mv[v];
  mv[v * 2 + 1] -= mv[v * 2 + 1] >= m ? m : 0;
  mv[v * 2 + 2] += mv[v];
  mv[v * 2 + 2] -= mv[v * 2 + 2] >= m ? m : 0;
  mv[v] = 0;
}
void upd(int lf, int rg, int val, int v = 0, int tl = 0, int tr = maxn - 1) {
  push(v, tl, tr);
  if (rg < tl || tr < lf) {
    return;
  }
  if (lf <= tl && tr <= rg) {
    mv[v] += val;
    mv[v] -= mv[v] >= m ? m : 0;
    push(v, tl, tr);
    return;
  }
  int tm = (tl + tr) >> 1;
  upd(lf, rg, val, v * 2 + 1, tl, tm);
  upd(lf, rg, val, v * 2 + 2, tm + 1, tr);
  deo[v] = (deo[v * 2 + 1] | deo[v * 2 + 2]);
}
bitset<1000> get(int lf, int rg, int v = 0, int tl = 0, int tr = maxn - 1) {
  push(v, tl, tr);
  if (rg < tl || tr < lf) {
    return bitset<1000>();
  }
  if (lf <= tl && tr <= rg) {
    return (deo[v]);
  }
  int tm = (tl + tr) >> 1;
  return (get(lf, rg, v * 2 + 1, tl, tm) | get(lf, rg, v * 2 + 2, tm + 1, tr));
}
void dfs(int u) {
  pm[u] = 1;
  lf[u] = sz;
  b[sz++] = u;
  for (int i = 0; i < (int)rb[u].size(); i++) {
    int v = rb[u][i];
    if (pm[v]) continue;
    dfs(v);
  }
  rg[u] = sz - 1;
}
int main() {
  {
    srand(time(0));
    const string file = "";
    if (!file.empty()) {
      freopen((file + ".in").c_str(), "r", stdin);
      freopen((file + ".out").c_str(), "w", stdout);
    }
  }
  rw[0] = rw[1] = 1;
  for (int i = 2; i < 1000; i++) {
    if (!rw[i]) {
      for (int j = i + i; j < 1000; j += i) {
        rw[j] = 1;
      }
    }
  }
  int n;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i] %= m;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    rb[u].push_back(v);
    rb[v].push_back(u);
  }
  for (int i = 0; i < m; i++) all[i] = 1;
  dfs(0);
  build();
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int v, x;
      scanf("%d%d", &v, &x);
      v--;
      upd(lf[v], rg[v], x % m);
    } else {
      int u;
      scanf("%d", &u);
      u--;
      bitset<1000> ans = get(lf[u], rg[u]);
      int cnt = 0;
      for (int i = 0; i < m; i++) {
        if (!rw[i] && ans[i] == 1) {
          cnt++;
        }
      }
      printf("%d\n", cnt);
    }
  }
  return (0);
}