#include <bits/stdc++.h>   using namespace std;   int st[200011], disc = 0, mod, en[200011];   vector<int> adj[200011];   bitset<1003> m[1000011];   int flag[1000011], a[200011];   int p[2011], arr[200011];   vector<int> pr;   bitset<1003> def;   void dfs(int u, int p) {     st[u] = disc;     arr[disc] = u;     disc++;     for (int i = 0; i < adj[u].size(); i++) {       int k = adj[u][i];       if (k == p) continue;       dfs(k, u);     }     en[u] = disc - 1;   }   void rotate(std::bitset<1003>& b, unsigned m) {     b = (((b << m) & def) | (b >> (mod - m)));   }   void build(int n, int b, int e) {     if (b == e) {       m[n].set(a[arr[b]]);       return;     }     int l = 2 * n, mid = (b + e) / 2;     build(l, b, mid);     build(l + 1, mid + 1, e);     m[n] = m[l] | m[l + 1];   }   void update(int n, int b, int e, int x, int y, int v) {     if (flag[n] != 0) {       rotate(m[n], flag[n]);       if (b != e) {         flag[2 * n] = (flag[2 * n] + flag[n]) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + flag[n]) % mod;       }       flag[n] = 0;     }     if (b > y || e < x) return;     if (b >= x && e <= y) {       rotate(m[n], v);       if (b != e) {         flag[2 * n] = (flag[2 * n] + v) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + v) % mod;       }       return;     }     int l = 2 * n, mid = (b + e) / 2;     update(l, b, mid, x, y, v);     update(l + 1, mid + 1, e, x, y, v);     m[n] = m[l] | m[l + 1];   }   bitset<1003> query(int n, int b, int e, int x, int y) {     if (flag[n] != 0) {       rotate(m[n], flag[n]);       if (b != e) {         flag[2 * n] = (flag[2 * n] + flag[n]) % mod;         flag[2 * n + 1] = (flag[2 * n + 1] + flag[n]) % mod;       }       flag[n] = 0;     }     if (b > y || e < x) return 0;     if (b >= x && e <= y) return m[n];     int l = 2 * n, mid = (b + e) / 2;     return (query(l, b, mid, x, y) | query(l + 1, mid + 1, e, x, y));   }   int main() {     int n, i, j, k;     scanf( %d %d , &n, &mod);     for (i = 2; i < mod; i++)       if (p[i] == 0) {         pr.push_back(i);         for (j = i + i; j < mod; j += i) p[j] = 1;       }     for (i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] %= mod;     for (i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     build(1, 0, n - 1);     int q;     scanf( %d , &q);     for (i = 0; i < mod; i++) def.set(i);     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int x, v;         scanf( %d %d , &v, &x);         x %= mod;         update(1, 0, n - 1, st[v], en[v], x);       } else {         int v, ans = 0;         scanf( %d , &v);         bitset<1003> b = query(1, 0, n - 1, st[v], en[v]);         for (int i = 0; i < pr.size(); i++)           if (b.test(pr[i])) ans++;         printf( %d n , ans);       }     }     return 0;   }   