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;
bitset<1000> primeMask;
bitset<1000> xd;
int isPrime(int N) {
  if (N < 2) return 0;
  for (int i = 2; i * i <= N; i++)
    if (N % i == 0) return 0;
  return 1;
}
int N, M;
struct node {
  bitset<1000> st;
  node() { st.reset(); }
  node merge(node &R) {
    node ret;
    ret.st = st | R.st;
    return ret;
  }
  void set(int x) { st.set(x); }
  void add(int x) {
    x %= M;
    if (!x) return;
    st = (st << x) | (st >> (M - x));
  }
};
const int maxn = 100100;
node segtree[4 * maxn];
int lazy[4 * maxn];
int arr[maxn];
int v[maxn];
void buildTree(int l, int r, int pos) {
  if (l == r) {
    segtree[pos].set(arr[l]);
    lazy[pos] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  buildTree(l, mid, 2 * pos);
  buildTree(mid + 1, r, 2 * pos + 1);
  segtree[pos] = segtree[2 * pos].merge(segtree[2 * pos + 1]);
  lazy[pos] = 0;
}
void lazyUpdate(int l, int r, int pos) {
  if (lazy[pos]) {
    segtree[pos].add(lazy[pos]);
    if (l != r) {
      lazy[2 * pos] += lazy[pos];
      lazy[2 * pos + 1] += lazy[pos];
      lazy[2 * pos] %= M;
      lazy[2 * pos + 1] %= M;
    }
    lazy[pos] = 0;
  }
}
void update(int lQ, int rQ, int val, int l, int r, int pos) {
  lazyUpdate(l, r, pos);
  if (l > r or lQ > rQ or l > rQ or r < lQ) return;
  if (l >= lQ && r <= rQ) {
    lazy[pos] = val;
    lazyUpdate(l, r, pos);
    return;
  }
  int mid = (l + r) >> 1;
  update(lQ, rQ, val, l, mid, 2 * pos);
  update(lQ, rQ, val, mid + 1, r, 2 * pos + 1);
  segtree[pos] = segtree[2 * pos].merge(segtree[2 * pos + 1]);
}
node query(int lQ, int rQ, int l, int r, int pos) {
  lazyUpdate(l, r, pos);
  node ret;
  if (l > r or lQ > rQ or l > rQ or r < lQ) return ret;
  if (l >= lQ && r <= rQ) return segtree[pos];
  int mid = (l + r) >> 1;
  node L = query(lQ, rQ, l, mid, 2 * pos);
  node R = query(lQ, rQ, mid + 1, r, 2 * pos + 1);
  ret = L.merge(R);
  return ret;
}
vector<int> edge[maxn];
int in[maxn], out[maxn];
int timer = 1;
void dfs(int u, int p) {
  in[u] = timer;
  arr[timer] = v[u];
  for (auto vv : edge[u]) {
    if (vv == p) continue;
    timer++;
    dfs(vv, u);
  }
  out[u] = timer;
}
int main() {
  xd.flip();
  scanf("%d", &N);
  scanf("%d", &M);
  for (int i = 2; i < M; i++)
    if (isPrime(i)) primeMask.set(i);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &v[i]);
    v[i] %= M;
  }
  for (int i = 1; i < N; i++) {
    int u, vv;
    scanf("%d", &u);
    scanf("%d", &vv);
    edge[u].push_back(vv);
    edge[vv].push_back(u);
  }
  dfs(1, 0);
  buildTree(1, N, 1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int type, vv;
    scanf("%d", &type);
    scanf("%d", &vv);
    int L = in[vv];
    int R = out[vv];
    if (type == 1) {
      int x;
      scanf("%d", &x);
      x %= M;
      if (x) update(L, R, x, 1, N, 1);
    } else {
      node x = query(L, R, 1, N, 1);
      x.st &= primeMask;
      printf("%d\n", x.st.count());
    }
  }
  return 0;
}