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;
using lli = long long int;
using llu = long long unsigned;
using pii = tuple<lli, lli>;
using ppii = tuple<pii, pii>;
using piii = tuple<lli, lli, lli>;
using vi = vector<lli>;
using vii = vector<pii>;
using viii = vector<piii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
using vviii = vector<viii>;
template <class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a) {
  return s << "(" << get<0>(a) << "," << get<1>(a) << ")";
}
template <class A, class B>
ostream& operator<<(ostream& s, tuple<A, B> const& a) {
  return s << "(" << get<0>(a) << "," << get<1>(a) << ")";
}
template <class A, class B, class C>
ostream& operator<<(ostream& s, tuple<A, B, C> const& a) {
  return s << "(" << get<0>(a) << "," << get<1>(a) << "," << get<2>(a) << ")";
}
template <class T>
ostream& print_collection(ostream& s, T const& a) {
  s << '[';
  for (auto it = begin(a); it != end(a); ++it) {
    s << *it;
    if (it != prev(end(a))) s << " ";
  }
  return s << ']';
}
template <class T, size_t I>
ostream& operator<<(ostream& s, array<T, I> const& a) {
  return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, vector<T> const& a) {
  return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) {
  return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) {
  return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, set<T> const& a) {
  return print_collection(s, a);
}
lli n, m;
bitset<1000> mask;
struct node {
  node() : bs() {}
  bitset<1000> bs;
  lli rotation = 0;
};
struct tree {
  lli n;
  vector<node> A;
  tree(lli n_) : n((lli)1 << (lli)(log2(n_) + 1)), A(2 * n) {}
  void print_tree_(lli i, lli a, lli b, lli in) {
    push(i, a, b);
    lli c = (a + b) / 2;
    if (i < n) print_tree_(2 * i, a, c, in + 1);
    for (lli i = 0; i < (lli)(in); ++i) cout << "  ";
    cout << "| " << i << " ";
    for (lli j = 0; j < (lli)(20); ++j) cout << (A[i].bs[j] ? 1 : 0);
    cout << endl;
    if (i < n) print_tree_(2 * i + 1, c + 1, b, in + 1);
  }
  void print_tree() { print_tree_(1, 0, n - 1, 0); }
  void push(lli i, lli a, lli b) {
    if (i < n) {
      lli c = (a + b) / 2;
      if (A[i].rotation) {
        rotate__(2 * i, a, c, A[i].rotation);
        rotate__(2 * i + 1, c + 1, b, A[i].rotation);
        A[i].rotation = 0;
      }
    }
  }
  void build() {
    for (lli i = (n - 1); i >= (lli)(0); --i) update(i);
  }
  void update(lli i) { A[i].bs = A[2 * i].bs | A[2 * i + 1].bs; }
  void rotate__(lli i, lli a, lli b, lli v) {
    v = ((v % m) + m) % m;
    A[i].bs = ((A[i].bs << v) | (A[i].bs >> (m - v))) & mask;
    (A[i].rotation += v) %= m;
  }
  void rotate_(lli i, lli a, lli b, lli l, lli r, lli v) {
    if (l > b) return;
    if (r < a) return;
    if (l <= a && b <= r) {
      rotate__(i, a, b, v);
      return;
    }
    push(i, a, b);
    lli c = (a + b) / 2;
    rotate_(2 * i, a, c, l, r, v);
    rotate_(2 * i + 1, c + 1, b, l, r, v);
    update(i);
  }
  void rotate(lli l, lli r, lli v) { rotate_(1, 0, n - 1, l, r, v); }
  bitset<1000> query_(lli i, lli a, lli b, lli l, lli r) {
    if (l > b) return bitset<1000>();
    if (r < a) return bitset<1000>();
    push(i, a, b);
    if (l <= a && b <= r) {
      return A[i].bs;
    }
    lli c = (a + b) / 2;
    return query_(2 * i, a, c, l, r) | query_(2 * i + 1, c + 1, b, l, r);
  }
  bitset<1000> query(lli l, lli r) { return query_(1, 0, n - 1, l, r); }
};
vi primes;
lli SIEVE[1002];
int main(int, char**) {
  for (lli i = (2); i <= (lli)(1000); ++i) SIEVE[i] = 1;
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (lli i = (2); i <= (lli)(m - 1); ++i)
    if (SIEVE[i]) {
      primes.push_back(i);
      lli k = 2;
      while (k * i <= m) {
        SIEVE[k * i] = 0;
        k += 1;
      }
    }
  for (lli i = 0; i < (lli)(m); ++i) mask[i] = 1;
  vi AS(n);
  for (lli i = 0; i < (lli)(n); ++i) cin >> AS[i];
  vvi A(n);
  for (lli i = 0; i < (lli)(n - 1); ++i) {
    lli x, y;
    cin >> x >> y;
    x -= 1;
    y -= 1;
    A[x].push_back(y);
    A[y].push_back(x);
  }
  vi FROM(n), TO(n);
  lli t = 0;
  function<void(lli, lli)> dfs = [&](lli i, lli p) {
    FROM[i] = t;
    t += 1;
    for (auto j : A[i])
      if (j != p) {
        dfs(j, i);
      }
    TO[i] = t - 1;
  };
  dfs(0, -1);
  tree tr(t);
  for (lli i = 0; i < (lli)(n); ++i) {
    tr.A[tr.n + FROM[i]].bs[AS[i] % m] = 1;
  }
  tr.build();
  lli q;
  cin >> q;
  for (lli i = 0; i < (lli)(q); ++i) {
    lli t, v;
    cin >> t >> v;
    v -= 1;
    if (t == 1) {
      lli x;
      cin >> x;
      tr.rotate(FROM[v], TO[v], x % m);
    } else {
      auto b = tr.query(FROM[v], TO[v]);
      lli r = 0;
      for (auto p : primes)
        if (b[p]) r += 1;
      cout << r << endl;
    }
  }
  return 0;
}