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;
void ga(int N, int *A) {
  for (int i(0); i < N; i++) scanf("%d", A + i);
}
long long P[(200005) >> 1] = {2}, L(1), cn[1 + ((200005) >> 6)];
void gen() {
  (cn[0 >> 6] |= 1ULL << ((0 & 63))), (cn[1 >> 6] |= 1ULL << ((1 & 63)));
  int Q(1 + sqrt((200005)));
  for (long long i(4); i < (200005); i += 2) (cn[i >> 6] |= 1ULL << ((i & 63)));
  for (int k(3); k <= Q; k += 2)
    if (!((cn[k >> 6] >> (k & 63)) & 1))
      for (long long h(k << 1), j(k * k); j < (200005); j += h)
        (cn[j >> 6] |= 1ULL << ((j & 63)));
  for (int i(3); i < (200005); i += 2)
    if (!((cn[i >> 6] >> (i & 63)) & 1)) P[L++] = i;
}
vector<int> g[(200005)];
int N, Q, A[(200005)], B[(200005)], E[(200005)], W[(200005)], a, b, c, C, M;
void dfs(int u, int p) {
  B[u] = C, W[C++] = A[u];
  for (auto &h : g[u])
    if (h ^ p) dfs(h, u);
  E[u] = C - 1;
}
bitset<1024> RT(bitset<1024> b, int m) { return b << m | b >> (M - m); }
bitset<1024> y, p;
struct sX {
  bitset<1024> G[2 * (200005)];
  int N, R[2 * (200005)];
  void clr(int u, int B, int E, int n) {
    if (B >= n) return;
    if (B == E) {
      G[u][W[B] % M] = 1;
      return;
    }
    clr(u << 1, B, (B + E) >> 1, n), clr(u << 1 | 1, (B + E) / 2 + 1, E, n);
    G[u] = G[u << 1] | G[u << 1 | 1];
  }
  void ini(int n) {
    N = 1 << (int(log2(n) - (1e-10)) + 1);
    (memset(R, 0, sizeof(R))), clr(1, 0, N - 1, n);
  }
  bitset<1024> gt(int u) { return RT(G[u], R[u]); }
  void ud(int b, int e, int r) { st(b, e, r, 1, 0, N - 1); }
  void st(int b, int e, int r, int u, int B, int E) {
    if (B > e || E < b) return;
    if (b <= B && e >= E) {
      R[u] += r, R[u] %= M;
      return;
    }
    st(b, e, r, u << 1, B, (B + E) >> 1),
        st(b, e, r, u << 1 | 1, (B + E) / 2 + 1, E);
    G[u] = gt(u << 1) | gt(u << 1 | 1);
  }
  bitset<1024> gt(int b, int e) { return gt(b, e, 1, 0, N - 1); }
  bitset<1024> gt(int b, int e, int u, int B, int E) {
    if (B > e || E < b) return y;
    if (b <= B && e >= E) return gt(u);
    return RT(gt(b, e, u << 1, B, (B + E) >> 1) |
                  gt(b, e, u << 1 | 1, (B + E) / 2 + 1, E),
              R[u]);
  }
} T;
int pm(bitset<1024> a) { return (p & a).count(); }
int main(void) {
  scanf("%d%d", &N, &M), ga(N, A), gen();
  for (int k(2); k < M; k++)
    if (!((cn[k >> 6] >> (k & 63)) & 1)) p[k] = 1;
  for (int i(0); i < N - 1; i++)
    scanf("%d%d", &a, &b), g[--b].push_back(--a), g[a].push_back(b);
  dfs(0, -1), T.ini(N);
  int Q;
  scanf("%d", &Q);
  for (int i(0); i < Q; i++) {
    scanf("%d%d", &a, &b), --b;
    if (a - 1)
      printf("%d\n", pm(T.gt(B[b], E[b])));
    else
      scanf("%d", &c), T.ud(B[b], E[b], c % M);
  }
  return 0;
}