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>
#pragma GCC optimize("-O3")
using namespace std;
template <typename T>
using pqmin = priority_queue<T, vector<T>, greater<T> >;
template <typename T>
using pqmax = priority_queue<T>;
template <typename T>
using V = vector<T>;
inline char gc() {
  static char buf[1 << 20], *h = buf, *t = buf;
  return (h == t && (t = (h = buf) + fread(buf, 1, 1 << 20, stdin), h == t)
              ? -1
              : *h++);
}
template <typename T>
inline bool read(T &x) {
  static int f;
  static char c;
  for (c = gc(), f = 1; !isdigit(c); c = gc()) {
    if (c == -1)
      return false;
    else if (c == 45)
      f = -1;
  }
  for (x = c - 48; isdigit(c = gc()); x = x * 10 + c - 48)
    ;
  return x *= f, true;
}
template <typename A, typename B>
inline bool read(A &x, B &y) {
  return read(x) && read(y);
}
template <typename A, typename B, typename C>
inline bool read(A &x, B &y, C &z) {
  return read(x) && read(y) && read(z);
}
const int N = 100005;
V<int> e[N];
int n, m;
int pos[N], fin[N], value[N], clk;
void change1(const int &pos, const int &x, int l, int r, int rt);
void dfs(int u, int fa) {
  pos[u] = ++clk;
  change1(clk, value[u], 1, n, 1);
  for (const int &v : e[u])
    if (v != fa) dfs(v, u);
  fin[u] = clk;
}
int lzy[N << 2];
bitset<1003> s[N << 2];
inline void my_add(int rt, int val) {
  val %= m;
  s[rt] = (s[rt] << val) | (s[rt] >> (m - val));
}
inline void push_up(int rt) { s[rt] = s[rt << 1] | s[rt << 1 | 1]; }
inline void add(int &x, int y) {
  x += y;
  if (x >= m) x -= m;
}
void push_down(int rt) {
  if (lzy[rt]) {
    add(lzy[rt << 1], lzy[rt]);
    add(lzy[rt << 1 | 1], lzy[rt]);
    my_add(rt << 1, lzy[rt]);
    my_add(rt << 1 | 1, lzy[rt]);
    lzy[rt] = 0;
  }
}
void change1(const int &pos, const int &x, int l, int r, int rt) {
  if (l == r) {
    s[rt].set(x);
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    change1(pos, x, l, mid, rt << 1);
  else
    change1(pos, x, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
void change(const int &L, const int &R, const int &x, int l, int r, int rt) {
  if (l >= L && r <= R) {
    my_add(rt, x);
    add(lzy[rt], x);
    return;
  }
  int mid = l + r >> 1;
  push_down(rt);
  if (L <= mid) change(L, R, x, l, mid, rt << 1);
  if (R > mid) change(L, R, x, mid + 1, r, rt << 1 | 1);
  push_up(rt);
}
bitset<1003> query(const int &L, const int &R, int l, int r, int rt) {
  if (l >= L && r <= R) return s[rt];
  int mid = l + r >> 1;
  push_down(rt);
  if (L > mid) return query(L, R, mid + 1, r, rt << 1 | 1);
  if (R <= mid) return query(L, R, l, mid, rt << 1);
  return query(L, R, l, mid, rt << 1) | query(L, R, mid + 1, r, rt << 1 | 1);
}
bitset<1003> p;
inline bool ck_prime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}
int main() {
  read(n, m);
  p.reset();
  for (int i = 2; i < m; ++i) p[i] = ck_prime(i);
  for (int i = 1; i <= n; ++i) read(value[i]), value[i] %= m;
  for (int i = 1, u, v; i < n; ++i) {
    read(u, v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 0);
  int Q;
  for (read(Q); Q--;) {
    static int tp, x, y;
    read(tp);
    if (tp == 1) {
      read(x, y);
      change(pos[x], fin[x], y % m, 1, n, 1);
    } else {
      read(x);
      printf("%d\n", (int)(p & query(pos[x], fin[x], 1, n, 1)).count());
    }
  }
  return 0;
}