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 ll = long long;
int const nmax = 100000;
int const sigma = 2000;
std::vector<std::vector<int>> g;
int start[1 + nmax], stop[1 + nmax], ptr = 0;
void dfs(int node, int parent) {
  start[node] = ++ptr;
  for (int h = 0; h < g[node].size(); h++) {
    int to = g[node][h];
    if (to != parent) dfs(to, node);
  }
  stop[node] = ptr;
}
bool isprime(int number) {
  if (number < 2) return 0;
  for (int i = 2; i * i <= number; i++)
    if (number % i == 0) return 0;
  return 1;
}
int m;
std::bitset<sigma> base;
std::bitset<sigma> shift(std::bitset<sigma> start, int k) {
  k %= m;
  std::bitset<sigma> result = (start << k);
  result = ((result & base) | (result >> m));
  return result & base;
}
class SegmentTree {
 private:
  std::vector<std::bitset<sigma>> aint;
  std::vector<int> lazy;
  void cleannode(int node, int from, int to) {
    if (lazy[node] == 0) return;
    if (from < to) {
      lazy[node * 2] += lazy[node];
      lazy[node * 2 + 1] += lazy[node];
    }
    aint[node] = shift(aint[node], lazy[node]);
    lazy[node] = 0;
  }
  void computenode(int node, int from, int to) {
    if (from < to) {
      int mid = (from + to) / 2;
      aint[node] = (aint[node * 2] | aint[node * 2 + 1]);
    }
  }

 public:
  SegmentTree(int n) {
    aint.resize(1 + 4 * n);
    lazy.resize(1 + 4 * n);
  }
  void build(int node, int from, int to, std::vector<int> &aux) {
    if (from < to) {
      int mid = (from + to) / 2;
      build(node * 2, from, mid, aux);
      build(node * 2 + 1, mid + 1, to, aux);
      computenode(node, from, to);
    } else
      aint[node][aux[from]] = 1;
  }
  void update(int node, int from, int to, int x, int y, int val) {
    if (from == x && to == y) {
      lazy[node] += val;
      cleannode(node, from, to);
    } else {
      int mid = (from + to) / 2;
      cleannode(node * 2, from, mid);
      cleannode(node * 2 + 1, mid + 1, to);
      if (x <= mid)
        update(node * 2, from, mid, x, (((y) < (mid)) ? (y) : (mid)), val);
      if (mid + 1 <= y)
        update(node * 2 + 1, mid + 1, to, (((mid + 1) < (x)) ? (x) : (mid + 1)),
               y, val);
      computenode(node, from, to);
    }
  }
  std::bitset<sigma> query(int node, int from, int to, int x, int y) {
    cleannode(node, from, to);
    if (from == x && to == y)
      return aint[node];
    else {
      int mid = (from + to) / 2;
      if (x <= mid && y <= mid)
        return query(node * 2, from, mid, x, y);
      else if (mid + 1 <= x && mid + 1 <= y)
        return query(node * 2 + 1, mid + 1, to, x, y);
      else
        return (query(node * 2, from, mid, x, mid) |
                query(node * 2 + 1, mid + 1, to, mid + 1, y));
    }
  }
};
void print(std::bitset<sigma> aux) {
  for (int i = 0; i < m; i++) std::cout << aux[i];
  std::cout << '\n';
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::bitset<2> mybitset;
  int n;
  std::cin >> n >> m;
  std::bitset<sigma> primemap;
  for (int i = 0; i < m; i++) base[i] = 1;
  for (int i = 0; i < m; i++) primemap[i] = isprime(i);
  std::vector<int> v(1 + n);
  for (int i = 1; i <= n; i++) std::cin >> v[i];
  g.resize(1 + n);
  for (int i = 1; i < n; i++) {
    int x, y;
    std::cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  std::vector<int> init(1 + n);
  for (int i = 1; i <= n; i++) init[start[i]] = v[i] % m;
  SegmentTree aint(n);
  aint.build(1, 1, n, init);
  int q;
  std::cin >> q;
  for (int i = 1; i <= q; i++) {
    int op;
    std::cin >> op;
    if (op == 1) {
      int x, val;
      std::cin >> x >> val;
      val %= m;
      aint.update(1, 1, n, start[x], stop[x], val);
    } else {
      int x;
      std::cin >> x;
      std::cout << (aint.query(1, 1, n, start[x], stop[x]) & primemap).count()
                << '\n';
    }
  }
  return 0;
}