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>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
template <class T>
using vec2d = std::vector<std::vector<T>>;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
struct Input {
  Input(istream& in) : in(&in) {}
  template <class T>
  T next() const {
    T x;
    *in >> x;
    return x;
  }
  int ni() const { return next<int>(); }
  template <class T>
  vec<T> nVec(int n) const {
    vec<T> v(n);
    for (int i = 0; i < n; ++i) {
      v[i] = next<T>();
    }
    return v;
  }
  vec<int> nvi(int n) const { return nVec<int>(n); }
  istream* in;
};
Input in(cin);
class Output {
 private:
  ostream* out;
  template <typename T>
  void printSingle(const T& value) {
    *out << value;
  }

 public:
  Output(ostream& out) : out(&out) {}
  inline void print() {}
  template <typename T, typename... Ts>
  inline void print(const T& f, const Ts&... args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
  }
  template <typename... Ts>
  inline void println(const Ts&... args) {
    print(args...);
    *out << '\n';
  }
  template <typename... Ts>
  inline void operator()(const Ts&... args) {
    println(args...);
  }
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
void buildSimpleDfsOrder(const vec2d<int>& tree, vec<int>& height,
                         vec<int>& tIn, vec<int>& tOut, vec<int>& dfsOrder,
                         int root = 0) {
  int timer = 0;
  int n = static_cast<int>(tree.size());
  height = vector<int>(n, -1);
  dfsOrder.clear();
  dfsOrder.reserve(n);
  tIn = vector<int>(n, -1);
  tOut = vector<int>(n, -1);
  std::function<void(int, int)> dfs = [&](int v, int h) {
    height[v] = h;
    dfsOrder.push_back(v);
    tIn[v] = timer++;
    for (int to : tree[v]) {
      if (height[to] != -1) {
        continue;
      }
      dfs(to, h + 1);
    }
    tOut[v] = timer - 1;
  };
  dfs(root, 0);
}
vector<int> getBitPrime(int limit) {
  vector<int> is_prime((limit + 31) >> 5, -1);
  if (limit < 2) {
    return vector<int>((limit + 31) >> 5);
  }
  is_prime[0] &= -4;
  for (int i = 2; i * i < limit; ++i) {
    if ((is_prime[i >> 5] >> (i & 31) & 1) == 1) {
      for (int j = i * i; j < limit; j += i) {
        is_prime[j >> 5] &= (-1 - (1 << (j & 31)));
      }
    }
  }
  return is_prime;
}
vector<int> getPrimes(int limit) {
  auto is_prime = getBitPrime(limit);
  vector<int> result;
  result.reserve(limit);
  for (int i = 0; i < (limit); ++i) {
    if ((is_prime[i >> 5] >> (i & 31) & 1) == 1) {
      result.push_back(i);
    }
  }
  return result;
}
vec<bitset<1000>> suffixMasks(1001), prefixMask(1001);
int m;
void prepareMasks() {
  suffixMasks[0] = prefixMask[0] = bitset<1000>();
  for (int i = 0; i < (m + 1); ++i)
    if (i) {
      suffixMasks[i] = suffixMasks[i - 1];
      prefixMask[i] = prefixMask[i - 1];
      suffixMasks[i].set(m - i);
      prefixMask[i].set(i - 1);
    }
}
struct Node {
  int l, r;
  bitset<1000> data;
  int shift;
  Node() {}
  Node(int l, int r, bitset<1000> a, bitset<1000> b)
      : l(l), r(r), data(a), shift(0) {
    data |= b;
  }
  Node(int l, int r, int x) : l(l), r(r) {
    data = bitset<1000>();
    data.set(x);
    shift = 0;
  }
  void combine(const Node& lhs, const Node& rhs) {
    data = (lhs.data | rhs.data);
  }
  void setShift(int by) {
    shift += by;
    shift %= m;
    ;
    ;
    if (by > 0) {
      bitset<1000> sufShift = suffixMasks[by];
      sufShift &= data;
      data ^= sufShift;
      sufShift >>= (m - by);
      data <<= (by);
      data |= sufShift;
    }
  }
  void push(Node& lhs, Node& rhs) {
    shift %= m;
    if (shift) {
      lhs.setShift(shift);
      rhs.setShift(shift);
      shift = 0;
    }
  }
};
struct SegmentTree {
  int n, N;
  vec<Node> tree;
  SegmentTree(int n, const vec<int>& a) : n(n) {
    tree.assign(4 * n, Node());
    build(1, 0, n, a);
  }
  void build(int v, int vl, int vr, const vec<int>& a) {
    if (vl + 1 == vr) {
      tree[v] = Node(vl, vr, a[vl]);
      return;
    }
    int vm = (vl + vr) / 2;
    build(2 * v, vl, vm, a);
    build(2 * v + 1, vm, vr, a);
    tree[v] = Node(vl, vr, tree[2 * v].data, tree[2 * v + 1].data);
  }
  void internalUpdate(int l, int r, int v, int vl, int vr, int by) {
    ;
    ;
    if (l >= vr || vl >= r) return;
    if (vl >= l && vr <= r) {
      tree[v].setShift(by);
      return;
    }
    tree[v].push(tree[2 * v], tree[2 * v + 1]);
    int vm = (vl + vr) / 2;
    internalUpdate(l, r, 2 * v, vl, vm, by);
    internalUpdate(l, r, 2 * v + 1, vm, vr, by);
    tree[v].combine(tree[2 * v], tree[2 * v + 1]);
  }
  void update(int l, int r, int by) { internalUpdate(l, r + 1, 1, 0, n, by); }
  bitset<1000> internalGet(int l, int r, int v, int vl, int vr) {
    if (l >= vr || vl >= r) return bitset<1000>();
    if (vl >= l && vr <= r) {
      return tree[v].data;
    }
    tree[v].push(tree[2 * v], tree[2 * v + 1]);
    int vm = (vl + vr) / 2;
    auto res = internalGet(l, r, 2 * v, vl, vm);
    res |= internalGet(l, r, 2 * v + 1, vm, vr);
    return res;
  }
  bitset<1000> get(int l, int r) { return internalGet(l, r + 1, 1, 0, n); }
};
void solve(istream& inStream, ostream& outStream) {
  in = Input(inStream);
  out = Output(outStream);
  auto n = in.ni();
  m = in.ni();
  prepareMasks();
  auto primes = getPrimes(m);
  if (primes.back() == m) {
    primes.pop_back();
  }
  bitset<1000> toAnd;
  for (auto p : primes) {
    toAnd.set(p);
  }
  auto a = in.nvi(n);
  for (int i = 0; i < (n); ++i) a[i] %= m;
  vec2d<int> g(n);
  for (int i = 0; i < (n - 1); ++i) {
    auto x = in.ni() - 1;
    auto y = in.ni() - 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vec<int> height, tIn, tOut, dfsOrder;
  buildSimpleDfsOrder(g, height, tIn, tOut, dfsOrder);
  ;
  ;
  ;
  ;
  ;
  ;
  vec<int> newA(a.size());
  for (int i = 0; i < (n); ++i) {
    newA[i] = a[dfsOrder[i]];
  }
  a = newA;
  ;
  ;
  SegmentTree stree(n, a);
  auto q = in.ni();
  for (int qi = 0; qi < (q); ++qi) {
    ;
    ;
    auto t = in.ni();
    auto v = in.ni() - 1;
    if (t == 1) {
      auto x = in.ni() % m;
      auto l = tIn[v], r = tOut[v];
      stree.update(l, r, x);
    } else {
      auto l = tIn[v], r = tOut[v];
      ;
      ;
      auto s = stree.get(l, r);
      ;
      ;
      s &= toAnd;
      out(s.count());
    }
  }
}
int main() {
  solve(cin, cout);
  return 0;
}