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;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T mdINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
template <class T>
bool ISLEFT(T a, T b, T c) {
  if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -
       (b.first.first - c.first.first) * (a.second.second - b.second.second)) <
      0.0)
    return 1;
  else
    return 0;
}
bool prv[1002];
int n, m, sz;
bitset<1001> bt;
void seive() {
  prv[1] = 1;
  for (int i = 2; i <= m; i++) {
    if (prv[i] == 0)
      for (int j = i * 2; j <= m; j += i) {
        prv[j] = 1;
      }
  }
  for (int i = 2; i < m; i++)
    if (prv[i] == 0) bt.set(i);
}
int a[100000 + 2];
vector<int> v[100000 + 2];
pair<int, int> ar[100000 + 2];
int kon[100000 + 2];
void dfs(int i, int p) {
  ar[i].first = ++sz;
  kon[sz] = i;
  for (int j = 0; j < v[i].size(); j++) {
    int first = v[i][j];
    if (first == p) continue;
    dfs(first, i);
  }
  ar[i].second = sz;
}
bitset<1001> tr[100000 * 4];
int lazy[100000 * 4];
void build(int no, int s, int e) {
  if (s == e) {
    tr[no].set(a[kon[s]] % m);
    return;
  }
  int mid = (s + e) >> 1;
  build(no * 2, s, mid);
  build(no * 2 + 1, mid + 1, e);
  tr[no] = tr[no * 2] | tr[no * 2 + 1];
}
void propagate(bitset<1001> &first, int l) {
  first = ((first << l)) | (first >> (m - l));
}
void update(int no, int s, int e, int st, int en, int val) {
  if (lazy[no]) {
    propagate(tr[no], lazy[no]);
    if (s != e) {
      lazy[no * 2] = (lazy[no * 2] + lazy[no]) % m;
      lazy[no * 2 + 1] = (lazy[no * 2 + 1] + lazy[no]) % m;
    }
    lazy[no] = 0;
  }
  if (e < st || s > en) return;
  if (s >= st && e <= en) {
    lazy[no] = (lazy[no] + val) % m;
    propagate(tr[no], lazy[no]);
    if (s != e) {
      lazy[no * 2] = (lazy[no * 2] + lazy[no]) % m;
      lazy[no * 2 + 1] = (lazy[no * 2 + 1] + lazy[no]) % m;
    }
    lazy[no] = 0;
    return;
  }
  int mid = (s + e) >> 1;
  update(no * 2, s, mid, st, en, val);
  update(no * 2 + 1, mid + 1, e, st, en, val);
  tr[no] = tr[no * 2] | tr[no * 2 + 1];
}
bitset<1001> now;
void query(int no, int s, int e, int st, int en) {
  if (lazy[no]) {
    propagate(tr[no], lazy[no]);
    if (s != e) {
      lazy[no * 2] = (lazy[no * 2] + lazy[no]) % m;
      lazy[no * 2 + 1] = (lazy[no * 2 + 1] + lazy[no]) % m;
    }
    lazy[no] = 0;
  }
  if (e < st || s > en) return;
  if (s >= st && e <= en) {
    now |= tr[no];
    return;
  }
  int mid = (s + e) >> 1;
  query(no * 2, s, mid, st, en);
  query(no * 2 + 1, mid + 1, e, st, en);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] %= m;
  seive();
  for (int j = 1; j < n; j++) {
    int first, second;
    scanf("%d%d", &first, &second);
    v[first].push_back(second);
    v[second].push_back(first);
  }
  dfs(1, 0);
  build(1, 1, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int first, second;
      scanf("%d%d", &first, &second);
      second %= m;
      update(1, 1, n, ar[first].first, ar[first].second, second);
    } else {
      int first;
      scanf("%d", &first);
      now.reset();
      query(1, 1, n, ar[first].first, ar[first].second);
      int ans = (now & bt).count();
      printf("%d\n", ans);
    }
  }
  return 0;
}