#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tt[N * 4], tout[N], timer = 0;
ll a[N];
bool mark[N], use[N * 4], zz = 0;
vector < int > g[N], pp;
bitset < 1001 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v];
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        int aa = b[tl];
        b[tl] %= m;
        if (aa != 0)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (!use[v])
        return;
    if (tl != tr)
    {
        p[v * 2] += p[v];
        use[v * 2] = 1;
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        use[v * 2 + 1] = 1;
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v])
    {
        t[v][p[v]] = 1;
        tt[v] = 0;
    }
    p[v] = 0;
    use[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        use[v] = 1;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N * 4], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    if (n > 1000)
    {
        cout << -1;
        return 0;
    }
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N], use[N * 4], zz = 0, tt[N * 4];
vector < int > g[N], pp;
bitset < 1001 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        if (a[tl] != 0)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (!use[v])
        return;
    if (tl != tr)
    {
        p[v * 2] += p[v];
        use[v * 2] = 1;
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        use[v * 2 + 1] = 1;
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v])
    {
        t[v][p[v]] = 1;
        tt[v] = 0;
    }
    p[v] = 0;
    use[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        use[v] = 1;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N], use[N * 4], zz = 0, tt[N * 4];
vector < int > g[N], pp;
bitset < 1001 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v];
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        int aa = b[tl];
        b[tl] %= m;
        if (aa != 0)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (!use[v])
        return;
    if (tl != tr)
    {
        p[v * 2] += p[v];
        use[v * 2] = 1;
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        use[v * 2 + 1] = 1;
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v])
    {
        t[v][p[v]] = 1;
        tt[v] = 0;
    }
    p[v] = 0;
    use[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        use[v] = 1;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4];

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    forn(i, n - 1)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        scanf("%d", &t);
        if (t == 1)
        {
            int v, x;
            scanf("%d %d", &v, &x);
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            scanf("%d", &v);
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            printf("%d\n", ans);
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N], use[N * 4], zz = 0, tt[N * 4];
vector < int > g[N], pp;
bitset < 1001 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        if (a[tl] != 0)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (!use[v])
        return;
    if (tl != tr)
    {
        p[v * 2] += p[v];
        use[v * 2] = 1;
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        use[v * 2 + 1] = 1;
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v])
    {
        t[v][p[v]] = 1;
        tt[v] = 0;
    }
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        use[v] = 1;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4];

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            printf("%d\n", ans);
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    forn(i, m)
        bb[i] = 0;
    forn(i, m)
        if (t[v][i] == 1)
        {
            int q = (i + p[v]) % m;
            bb[q] = 1;
        }
    t[v] = bb;
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4];

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            scanf("%d", &v);
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            printf("%d\n", ans);
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N * 4], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = t[v] << p[v];
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    t[v] = t[v] << p[v];
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N], zz = 0, tt[N * 4];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        if (a[tl] != 0 || !zz)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v])
    {
        tt[v] = 0;
        t[v][p[v]] = 1;
    }
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4];

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

int get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        scanf("%I64d", &a[i]);
    forn(i, n - 1)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        scanf("%d", &t);
        if (t == 1)
        {
            int v, x;
            scanf("%d %d", &v, &x);
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            scanf("%d", &v);
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            printf("%d\n", ans);
        }
        if (u > 10000)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 300 > t[N * 4], bb;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

bool get(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[v][val];
    else
    {
        int tm = (tl + tr) / 2;
        return get(v * 2, tl, tm, l, min(r, tm), val) | get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i < m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            forn(i, sz(pp))
                if (get(1, 1, n, tin[v], tout[v], pp[i]))
                    ans++;
            cout << ans << endl;
        }
        if (u > 10)
        {
            cout << q << endl;
            return 0;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
        t[v][b[tl]] = 1;
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include "bits/stdc++.h"

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "parades"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("29", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const ll INF64 = 9e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384626433832795028841;
const ll MD = 925262732;
const ll T = 634521;
const int N = 200100;
const int M = 201;

int n, m, p[N * 4], b[N], q, tin[N], tout[N], timer = 0;
ll a[N];
bool mark[N], zz = 0, tt[N * 4], p1[N * 4];
vector < int > g[N], pp;
bitset < 1000 > t[N * 4], bb, ww;

void dfs(int v)
{
    tin[v] = ++timer;
    b[timer] = a[v] % m;
    forn(i, sz(g[v]))
        if (!tin[g[v][i]])
            dfs(g[v][i]);
    tout[v] = timer;
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        if (a[tl] != 0 || !zz)
            t[v][b[tl]] = 1;
        else
            tt[v] = 1;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        t[v] = t[v * 2] | t[v * 2 + 1];
        tt[v] = tt[v * 2] | tt[v * 2 + 1];
    }
}

void push(int v, int tl, int tr)
{
    if (tl != tr)
    {
        p[v * 2] += p[v];
        p1[v * 2] |= p1[v];
        p[v * 2] %= m;
        p[v * 2 + 1] += p[v];
        p1[v * 2 + 1] |= p1[v];
        p[v * 2 + 1] %= m;
    }
    p[v] %= m;
    t[v] = (t[v] << p[v]) | (t[v] >> (m - p[v]));
    if (tt[v] && p1[v])
    {
        tt[v] = 0;
        t[v][p[v]] = 1;
    }
    p[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int val)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        p[v] += val;
        p1[v] = 1;
        p[v] %= m;
        push(v, tl, tr);
    }
    else
    {
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), val);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
        t[v] = t[v * 2] | t[v * 2 + 1];
    }
}

void get(int v, int tl, int tr, int l, int r)
{
    push(v, tl, tr);
    if (l > r)
        return;
    if (tl == l && tr == r)
        ww = ww | t[v];
    else
    {
        int tm = (tl + tr) / 2;
        get(v * 2, tl, tm, l, min(r, tm));
        get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 2; i <= m; i++)
        if (!mark[i])
        {
            pp.pb(i);
            if (i == m)
            {
                pp.pb(0);
                zz = 1;
                break;
            }
            int j = i * i;
            while (j <= m)
            {
                mark[j] = 1;
                j += i;
            }
        }
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    forn(i, n - 1)
    {
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    build(1, 1, n);
    cin >> q;
    forn(u, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int v, x;
            cin >> v >> x;
            if (x != 0)
                update(1, 1, n, tin[v], tout[v], x);
        }
        else
        {
            int v;
            cin >> v;
            int ans = 0;
            ww = 0;
            get(1, 1, n, tin[v], tout[v]);
            forn(i, sz(pp))
                if (ww[pp[i]])
                    ans++;
            cout << ans << endl;
        }
    }
    return 0;

}

/*

*/


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 100000 + 3;
int n , m , Q;
vector<int> V[maxn];
int a[maxn];

void ReadData() {
    scanf("%d%d" , &n , &m);
    For(i , 1 , n) scanf("%d" , &a[i]);
    For(i , 1 , n - 1) {
        int u , v; scanf("%d%d" , &u , &v);
        V[u].push_back(v); V[v].push_back(u);
    }
    scanf("%d" , &Q);
}

int timer = 0, tin[maxn] , tout[maxn] , euler[maxn];

inline void dfs(const int u , const int prev) {
    tin[u] = ++timer;
    euler[timer] = u;
    Rep(i , sz(V[u])) {
        int v = V[u][i]; if ( v == prev ) continue;
        dfs(v , u);
    }
    tout[u] = timer;
}

int l[maxn * 4] , h[maxn * 4] , lazy[maxn * 4];
bitset<1000> it[maxn * 4] , P[1004];

void Rotate(bitset<1000> &a , int r) {
    if (!r) return;
    int l = m - r;
    a = ( ((a & P[r]) >> l) | ((a << r) & P[m]) );
}

void Build(const int &x , const int &low , const int &high) {
    l[x] = low; h[x] = high;
    if (low == high) {
        it[x] = bitset<1000>(0);
        it[x].set( a[euler[low]] % m , 1);
    } else {
        int mid = (low + high) >> 1;
        Build(LL(x) , low , mid);
        Build(RR(x) , mid + 1 , high);
        it[x] = (it[LL(x)] | it[RR(x)]);
    }
}

void Add(int x , int val) {
    lazy[x] = (lazy[x] + val) % m;
    Rotate(it[x] , val);
}

void Down(int x) {
    if (lazy[x]) {
        Add(LL(x) , lazy[x]);
        Add(RR(x) , lazy[x]);
        lazy[x] = 0;
    }
}

void Update(const int x , const int u , const int v , int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
        Add(x , val);
        return;
    }
    Down(x);
    Update(LL(x) , u , v , val);
    Update(RR(x) , u , v , val);
    it[x] = it[LL(x)] | it[RR(x)];
}

bitset<1000> Query(const int x , const int u , const int v) {
    if (l[x] > v || h[x] < u) return P[0];
    if (u <= l[x] && h[x] <= v) return it[x];
    Down(x);
    return Query(LL(x) , u , v) | Query(RR(x) , u , v);
}

bool isPrime(int x) {
    if (x == 2 || x % 2 == 0) return false;
    for (int i = 3 ; i * i <= x ; i += 2) if (x % i == 0) return false;
    return true;
}

vector<int> Prime;

void Process() {
    For(i , 1 , m) P[i] = P[i - 1] , P[i].set(m - i , 1);
    For(i , 3 , m - 1) if (isPrime(i)) Prime.push_back(i);
    dfs(1 , 0);
    Build(1 , 1 , n);

    while (Q--) {
        int type; scanf("%d" , &type);
        if (type == 1) {
            int u , x; scanf("%d%d" , &u , &x);
            Update(1 , tin[u] , tout[u] , x % m);
        } else {
            int u; scanf("%d" , &u);
            bitset<1000> lol = Query(1 , tin[u] , tout[u]);
            int res = 0;
            Rep(i , sz(Prime)) if (lol[Prime[i]]) res ++;
            cout << res << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 100000 + 3;
int n , m , Q;
vector<int> V[maxn];
int a[maxn];

void ReadData() {
    scanf("%d%d" , &n , &m);
    For(i , 1 , n) scanf("%d" , &a[i]);
    For(i , 1 , n - 1) {
        int u , v; scanf("%d%d" , &u , &v);
        V[u].push_back(v); V[v].push_back(u);
    }
    scanf("%d" , &Q);
}

int timer = 0, tin[maxn] , tout[maxn] , euler[maxn];

inline void dfs(const int u , const int prev) {
    tin[u] = ++timer;
    euler[timer] = u;
    Rep(i , sz(V[u])) {
        int v = V[u][i]; if ( v == prev ) continue;
        dfs(v , u);
    }
    tout[u] = timer;
}

int l[maxn * 4] , h[maxn * 4] , lazy[maxn * 4];
bitset<1000> it[maxn * 4] , P[1004];

void Rotate(bitset<1000> &a , int r) {
    if (!r) return;
    int l = m - r;
    a = ( ((a & P[r]) >> l) | ((a << r) & P[m]) );
}

void Build(const int &x , const int &low , const int &high) {
    l[x] = low; h[x] = high;
    if (low == high) {
        it[x] = bitset<1000>(0);
        it[x].set( a[euler[low]] % m , 1);
    } else {
        int mid = (low + high) >> 1;
        Build(LL(x) , low , mid);
        Build(RR(x) , mid + 1 , high);
        it[x] = (it[LL(x)] | it[RR(x)]);
    }
}

void Add(int x , int val) {
    lazy[x] = (lazy[x] + val) % m;
    Rotate(it[x] , val);
}

void Down(int x) {
    if (lazy[x]) {
        Add(LL(x) , lazy[x]);
        Add(RR(x) , lazy[x]);
        lazy[x] = 0;
    }
}

void Update(const int x , const int u , const int v , int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
        Add(x , val);
        return;
    }
    Down(x);
    Update(LL(x) , u , v , val);
    Update(RR(x) , u , v , val);
    it[x] = it[LL(x)] | it[RR(x)];
}

bitset<1000> Query(const int x , const int u , const int v) {
    if (l[x] > v || h[x] < u) return P[0];
    if (u <= l[x] && h[x] <= v) return it[x];
    Down(x);
    return Query(LL(x) , u , v) | Query(RR(x) , u , v);
}

bool isPrime(int x) {
    if (x == 2) return true;
    if (x == 2 || x % 2 == 0) return false;
    for (int i = 3 ; i * i <= x ; i += 2) if (x % i == 0) return false;
    return true;
}

vector<int> Prime;

void Process() {
    For(i , 1 , m) P[i] = P[i - 1] , P[i].set(m - i , 1);
    For(i , 2 , m - 1) if (isPrime(i)) Prime.push_back(i);
    dfs(1 , 0);
    Build(1 , 1 , n);

    while (Q--) {
        int type; scanf("%d" , &type);
        if (type == 1) {
            int u , x; scanf("%d%d" , &u , &x);
            Update(1 , tin[u] , tout[u] , x % m);
        } else {
            int u; scanf("%d" , &u);
            bitset<1000> lol = Query(1 , tin[u] , tout[u]);
            int res = 0;
            Rep(i , sz(Prime)) if (lol[Prime[i]]) res ++;
            cout << res << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 100000 + 3;
int n , m , Q;
vector<int> V[maxn];
int a[maxn];

void ReadData() {
    scanf("%d%d" , &n , &m);
    For(i , 1 , n) scanf("%d" , &a[i]);
    For(i , 1 , n - 1) {
        int u , v; scanf("%d%d" , &u , &v);
        V[u].push_back(v); V[v].push_back(u);
    }
    scanf("%d" , &Q);
}

int timer = 0, tin[maxn] , tout[maxn] , euler[maxn];

inline void dfs(const int u , const int prev) {
    tin[u] = ++timer;
    euler[timer] = u;
    Rep(i , sz(V[u])) {
        int v = V[u][i]; if ( v == prev ) continue;
        dfs(v , u);
    }
    tout[u] = timer;
}

int l[maxn * 4] , h[maxn * 4] , lazy[maxn * 4];
bitset<1001> it[maxn * 4] , P[1004];

void Rotate(bitset<1001> &a , int r) {
    if (!r) return;
    int l = m - r;
    a = ( ((a & P[r]) >> l) | ((a >> r) & P[m]) );
}

void Build(const int &x , const int &low , const int &high) {
    l[x] = low; h[x] = high;
    if (low == high) {
        it[x] = bitset<1001>(0);
        it[x].set( a[euler[low]] % m , 1);
    } else {
        int mid = (low + high) >> 1;
        Build(LL(x) , low , mid);
        Build(RR(x) , mid + 1 , high);
        it[x] = (it[LL(x)] | it[RR(x)]);
    }
}

void Add(int x , int val) {
    lazy[x] = (lazy[x] + val) % m;
    Rotate(it[x] , val);
}

void Down(int x) {
    if (lazy[x]) {
        Add(LL(x) , lazy[x]);
        Add(RR(x) , lazy[x]);
        lazy[x] = 0;
    }
}

void Update(const int x , const int u , const int v , int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
        Add(x , val);
        return;
    }
    Down(x);
    Update(LL(x) , u , v , val);
    Update(RR(x) , u , v , val);
    it[x] = it[LL(x)] | it[RR(x)];
}

bitset<1001> Query(const int x , const int u , const int v) {
    if (l[x] > v || h[x] < u) return P[0];
    if (u <= l[x] && h[x] <= v) return it[x];
    Down(x);
    return Query(LL(x) , u , v) | Query(RR(x) , u , v);
}

bool isPrime(int x) {
    if (x == 2 || x % 2 == 0) return false;
    for (int i = 3 ; i * i <= x ; i += 2) if (x % i == 0) return false;
    return true;
}

vector<int> Prime;

void Process() {
    For(i , 1 , m) P[i] = P[i - 1] , P[i].set(m - i , 1);
    For(i , 3 , m - 1) if (isPrime(i)) Prime.push_back(i);
    dfs(1 , 0);
    Build(1 , 1 , n);

    while (Q--) {
        int type; scanf("%d" , &type);
        if (type == 1) {
            int u , x; scanf("%d%d" , &u , &x);
            Update(1 , tin[u] , tout[u] , x % m);
        } else {
            int u; scanf("%d" , &u);
            bitset<1001> lol = Query(1 , tin[u] , tout[u]);
            int res = 0;
            Rep(i , sz(Prime)) if (lol[Prime[i]]) res ++;
            cout << res << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 100000 + 3;
int n , m , Q;
vector<int> V[maxn];
int a[maxn];

void ReadData() {
    scanf("%d%d" , &n , &m);
    For(i , 1 , n) scanf("%d" , &a[i]);
    For(i , 1 , n - 1) {
        int u , v; scanf("%d%d" , &u , &v);
        V[u].push_back(v); V[v].push_back(u);
    }
    scanf("%d" , &Q);
}

int timer = 0, tin[maxn] , tout[maxn] , euler[maxn];

inline void dfs(const int u , const int prev) {
    tin[u] = ++timer;
    euler[timer] = u;
    Rep(i , sz(V[u])) {
        int v = V[u][i]; if ( v == prev ) continue;
        dfs(v , u);
    }
    tout[u] = timer;
}

int l[maxn * 4] , h[maxn * 4] , lazy[maxn * 4];
bitset<1001> it[maxn * 4] , P[1004];

void Rotate(bitset<1001> &a , int r) {
    if (!r) return;
    int l = m - r;
    a = ( ((a & P[r]) >> l) | ((a << r) & P[m]) );
}

void Build(const int &x , const int &low , const int &high) {
    l[x] = low; h[x] = high;
    if (low == high) {
        it[x] = bitset<1001>(0);
        it[x].set( a[euler[low]] % m , 1);
    } else {
        int mid = (low + high) >> 1;
        Build(LL(x) , low , mid);
        Build(RR(x) , mid + 1 , high);
        it[x] = (it[LL(x)] | it[RR(x)]);
    }
}

void Add(int x , int val) {
    lazy[x] = (lazy[x] + val) % m;
    Rotate(it[x] , val);
}

void Down(int x) {
    if (lazy[x]) {
        Add(LL(x) , lazy[x]);
        Add(RR(x) , lazy[x]);
        lazy[x] = 0;
    }
}

void Update(const int x , const int u , const int v , int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
        Add(x , val);
        return;
    }
    Down(x);
    Update(LL(x) , u , v , val);
    Update(RR(x) , u , v , val);
    it[x] = it[LL(x)] | it[RR(x)];
}

bitset<1001> Query(const int x , const int u , const int v) {
    if (l[x] > v || h[x] < u) return P[0];
    if (u <= l[x] && h[x] <= v) return it[x];
    Down(x);
    return Query(LL(x) , u , v) | Query(RR(x) , u , v);
}

bool isPrime(int x) {
    if (x == 2 || x % 2 == 0) return false;
    for (int i = 3 ; i * i <= x ; i += 2) if (x % i == 0) return false;
    return true;
}

vector<int> Prime;

void Process() {
    For(i , 1 , m) P[i] = P[i - 1] , P[i].set(m - i , 1);
    For(i , 3 , m - 1) if (isPrime(i)) Prime.push_back(i);
    dfs(1 , 0);
    Build(1 , 1 , n);

    while (Q--) {
        int type; scanf("%d" , &type);
        if (type == 1) {
            int u , x; scanf("%d%d" , &u , &x);
            Update(1 , tin[u] , tout[u] , x % m);
        } else {
            int u; scanf("%d" , &u);
            bitset<1001> lol = Query(1 , tin[u] , tout[u]);
            int res = 0;
            Rep(i , sz(Prime)) if (lol[Prime[i]]) res ++;
            cout << res << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>

using namespace std;
const long double eps = 1e-12;

typedef long long ll;
typedef pair<int , int> pt;

#define sz(a) ((int) a.size() )
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)
#define For(i , a , b) for (int i = a ; i <= b ; i++)
#define Ford(i , a , b) for (int i = a ; i >= b ; i--)
#define Rep(i , n) for (int i = 0 ; i < n ; i++)

const int maxn = 100000 + 3;
int n , m , Q;
vector<int> V[maxn];
int a[maxn];

void ReadData() {
    scanf("%d%d" , &n , &m);
    For(i , 1 , n) scanf("%d" , &a[i]);
    For(i , 1 , n - 1) {
        int u , v; scanf("%d%d" , &u , &v);
        V[u].push_back(v); V[v].push_back(u);
    }
    scanf("%d" , &Q);
}

int timer = 0, tin[maxn] , tout[maxn] , euler[maxn];

inline void dfs(const int u , const int prev) {
    tin[u] = ++timer;
    euler[timer] = u;
    Rep(i , sz(V[u])) {
        int v = V[u][i]; if ( v == prev ) continue;
        dfs(v , u);
    }
    tout[u] = timer;
}

int l[maxn * 4] , h[maxn * 4] , lazy[maxn * 4];
bitset<1001> it[maxn * 4] , P[1004];

void Rotate(bitset<1001> &a , int r) {
    if (!r) return;
    int l = m - r;
    a = ( ((a >> l) & P[m]) | ((a & P[m]) << r) );
}

void Build(const int &x , const int &low , const int &high) {
    l[x] = low; h[x] = high;
    if (low == high) {
        it[x] = bitset<1001>(0);
        it[x].set( a[euler[low]] % m , 1);
    } else {
        int mid = (low + high) >> 1;
        Build(LL(x) , low , mid);
        Build(RR(x) , mid + 1 , high);
        it[x] = (it[LL(x)] | it[RR(x)]);
    }
}

void Add(int x , int val) {
    lazy[x] = (lazy[x] + val) % m;
    Rotate(it[x] , val);
}

void Down(int x) {
    if (lazy[x]) {
        Add(LL(x) , lazy[x]);
        Add(RR(x) , lazy[x]);
        lazy[x] = 0;
    }
}

void Update(const int x , const int u , const int v , int val) {
    if (l[x] > v || h[x] < u) return;
    if (u <= l[x] && h[x] <= v) {
        Add(x , val);
        return;
    }
    Down(x);
    Update(LL(x) , u , v , val);
    Update(RR(x) , u , v , val);
    it[x] = it[LL(x)] | it[RR(x)];
}

bitset<1001> Query(const int x , const int u , const int v) {
    if (l[x] > v || h[x] < u) return P[0];
    if (u <= l[x] && h[x] <= v) return it[x];
    Down(x);
    return Query(LL(x) , u , v) | Query(RR(x) , u , v);
}

bool isPrime(int x) {
    if (x == 2 || x % 2 == 0) return false;
    for (int i = 3 ; i * i <= x ; i += 2) if (x % i == 0) return false;
    return true;
}

vector<int> Prime;

void Process() {
    For(i , 1 , m) P[i] = P[i - 1] , P[i].set(m - i , 1);
    For(i , 3 , m - 1) if (isPrime(i)) Prime.push_back(i);
    dfs(1 , 0);
    Build(1 , 1 , n);

    while (Q--) {
        int type; scanf("%d" , &type);
        if (type == 1) {
            int u , x; scanf("%d%d" , &u , &x);
            Update(1 , tin[u] , tout[u] , x % m);
        } else {
            int u; scanf("%d" , &u);
            bitset<1001> lol = Query(1 , tin[u] , tout[u]);
            int res = 0;
            Rep(i , sz(Prime)) if (lol[Prime[i]]) res ++;
            cout << res << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //  freopen("/users/youaremysky/documents/workspace/input.inp" , "r" , stdin);
    ReadData();
    Process();
}


// ==========================================================================
//
//                Starting by the name of Almighty Allah
//
// ==========================================================================

#include<bits/stdc++.h>

#include <algorithm>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <deque>
#include <climits>
#include <complex>
#include <bitset>

using namespace std;

#define LL                          long long
#define ULL                         unsigned long long

// I/O
#define I(X)                        scanf("%d",     &(X))
#define II(X, Y)                    scanf("%d%d",   &(X), &(Y))
#define III(X, Y, Z)                scanf("%d%d%d", &(X), &(Y), &(Z))

#define IL(X)                       scanf("%lld", &X)
#define IIL(X,Y )                   scanf("%lld%lld", &X,&Y)
#define IIIL(X,Y,Z)                 scanf("%lld%lld%lld", &X,&Y,&Z)

#define ID(x)                       scanf("%lf",&x)
#define IID(x,y)                    scanf("%lf%lf",&x,&y)
#define IIID(x,y,z)                 scanf("%lf%lf%lf",&x,&y,&z)

#define DI(X)         int X;        I(X);
#define DII(X, Y)     int X, Y;     II(X,Y)
#define DIII(X, Y, Z) int X, Y, Z;  III(X,Y,Z);

#define DIL(X)        LL X;         IL(X)
#define DIIL(X,Y)     LL X,Y;       IIL(X,Y)
#define DIIIL(X,Y,Z)  LL X,Y,Z;     IIIL(X,Y,Z)

#define DDI(x)        double x;     ID(x);
#define DDII(x,y)     double x,y;   IID(x,y);
#define DDDII(x,y,z)  double x,y,z; IIID(x,y,z);

#define SS(s)                       scanf("%s",s)

#define PI(x)                       printf("%d\n",      x)
#define PII(x,y)                    printf("%d %d\n",   x,y)
#define PIII(x,y,z)                 printf("%d %d %d\n",x,y,z)

#define PIL(x)                      printf("%lld\n",          x)
#define PIIL(x,y)                   printf("%lld %lld\n",     x,y)
#define PIIIL(x,y,z)                printf("%lld %lld %lld\n",x,y,z)

// LOOP
#define rep(i,a,b)                  for(int i=a;i<=b;i++)
#define rev(i,a,b)                  for(int i=a;i>=b;i--)
#define repv(i,a)                   for(int i=0;i<(int)a.size();i++)
#define revv(i,a)                   for(int i=((int)a.size())-1;i>=0;i--)

#define FS(x)                       for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x)                       for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) {  cout << *it << " "; } cout << endl;

// array initialization
#define MEM(a,val)                  memset(a,val,sizeof(a));
#define SET(a)                      memset(a,-1,sizeof a)
#define CLR(a)                      memset(a,0,sizeof a)

// min-max
#define Max(a,b)                    (a>b?a:b)
#define Min(a,b)                    (a<b?a:b)
#define _Max(a,b,c)                 Max(a,Max(b,c))
#define _Min(a,b,c)                 Min(a,Min(b,c))
#define MAX(a)                      (*max_element(all(a)))
#define MIN(a)                      (*min_element(all(a)))

#define FastMax(x,y)                ((((y-x)>>(32-1))&(x^y))^y)
#define FastMin(x,y)                ((((y-x)>>(32-1))&(x^y))^x)

#define SQR(n)          ((n)*(n))

#define all(a)          a.begin(),a.end()
#define PB              push_back
#define NL              puts("");
#define pline           cout << "_________________________" << endl;
// pair
#define XX              first
#define YY              second
// binary search
#define LB(a,x)         (lower_bound(all(a),x)-a.begin())
#define UB(a,x)         (upper_bound(all(a),x)-a.begin())

//#define SI(X)           X=in<int>()
//#define SII(X,Y)        X=in<int>(),Y=in<int>()
//#define SIII(X,Y,Z)     X=in<int>(),Y=in<int>(),Z=in<int>()
//
//#define SL(X)           X=in<LL>()
//#define SLL(X,Y)        X=in<LL>(),Y=in<LL>()
//#define SLLL(X,Y,Z)     X=in<LL>(),Y=in<LL>(),Z=in<LL>()

//#define SEG             int mid=(s+e)>>1,l=(idx<<1),r=(l|1);
#define in(l,x,r)       ( l<=x && x<=r )

// Bit-op
#define countbit(x)     __builtin_popcount(x)
template< class T, class X > inline bool checkbit(T a, X pos) { T t=1;return ((a&(t<<pos))>0);  }
template< class T, class X > inline T      setbit(T a, X pos) { T t=1;return (a|(t<<pos));      }
template< class T, class X > inline T    resetbit(T a, X pos) { T t=1;return (a&(~(t<<pos)));   }
template< class T, class X > inline T   togglebit(T a, X pos) { T t=1;return (a^(t<<pos));      }
// mathematics
template<typename T> T POW(T base,T power)              { T ret=1; while(power)  { if(power & 1) ret=(ret*base); base=(base*base);  power>>=1; }return ret; }
template<typename T> T PPOW(T B,T P)                    { if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T> T Bigmod(T base,T power,T mod)     { T ret=1; while(power)  { if(power & 1) ret=(ret*base)%mod; base=(base*base)%mod;  power>>=1; }return ret; }
template<typename T> T ModInverse(T number,T mod)       { return Bigmod(number,mod-2,mod); }
template<typename T> T GCD(T a,T b)                     { if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<typename T> T LCM(T a,T b)                     { if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<typename T> T EUCLIDE(T a,T b,T &x,T &y)       { if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<typename T> T ABS(T a)                         { if(a<0)return -a;else return a;}
// geometry
template<typename T> double DIS(T x1,T y1,T x2, T y2)   { return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2)      { return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c)             { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
// Degree and Radian
//double DEG(double x) { return (180.0*x)/(M_PI*1.0);}
//double RAD(double x) { return (x*(M_PI*1.0))/(180.0);}

// debug
void P_ARR(int *ar,int a,int b) {  if(a>b) swap(a,b); if(a<=b) cout << ar[a]; for(int i=a+1;i<=b;i++) cout << " "<<ar[i];  cout << endl; }
template<typename T> T In(){ char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break;} if (ch>='0' && ch<='9') break; }    while (1) { n = n*10 + (ch - '0'); ch = getchar(); if (ch<'0' || ch>'9')   break;    }  return (ng?-n:n);  }

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};                                    /// month
//int dir[5][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1} };                                  /// 4 Direction
//int dir[9][2] = { {0,0},{1,0},{0,1},{-1,0},{0,-1},{-1,1},{-1,-1},{1,-1},{1,1}};       /// 8 direction
//int dir[9][2] = { {0,0},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1} };    /// Knight Direction
//int dir[8][2] = { {0,0},{2,0},{1,1},{-1,1} ,{-2,0} , {-1,-1} ,{1,-1} };               /// Hexagonal Direction
// dir[][0] = x value, dir[][1] = y value

/// ======================================================================================================
#define  debug  0
#define  AA     if(debug)
#define  eps     (1e-7)
#define  pi      (2.0*acos(0.0)) //#define PI acos(-1.0)
// IO
#define  READ   freopen("C:\\Users\\shaheen\\Desktop\\input.txt","r",stdin)
#define  WRITE  freopen("C:\\Users\\shaheen\\Desktop\\output.txt","w",stdout)
#define  _cin   ios_base::sync_with_stdio(0); cin.tie(0);
#define  F      fflush(stdout)
#define  FF     cout << flush
//              0123456789
#define  MX     400007
#define  MOD    1000000007LL
#define  inf    1000000000

#define  mask    bitset<1001>

mask tree[MX];
int ar[MX];
int st[MX],ed[MX];
vector<int>adj[MX];
int id[MX];
int cl;

void push_up(int idx,int l,int r) {
    tree[idx] = (tree[l]|tree[r]);
}

void build(int idx,int s,int e) {
    if(s==e) {
        tree[idx].set(ar[ id[s] ]);
        return;
    }
    int mid = (s+e)>>1 , l = (idx<<1) , r = (l|1);
    build(l,s,mid);
    build(r,mid+1,e);
    tree[idx] = (tree[l]|tree[r]);
}

int lazy[MX];
int md;

void Rotate(int idx,int v)
{
    tree[idx]= ( (tree[idx]<<v) | (tree[idx]>>(md-v)) );
}

void push_down(int idx,int l,int r)
{
    Rotate(l,lazy[idx]);
    Rotate(r,lazy[idx]);

    lazy[l] = (lazy[l]+lazy[idx]) % md;
    lazy[r] = (lazy[r]+lazy[idx]) % md;

    lazy[idx] = 0;
}

void update(int idx,int s,int e,int x,int y,int v) {

    if(s==x && e==y) {
        lazy[idx]=(lazy[idx]+v)%md;
        Rotate(idx,v);
        return;
    }

    int mid = (s+e)>>1 , l = (idx<<1) , r = (l|1);

    if(lazy[idx]) push_down(idx,l,r);

    if(y<=mid)      update(l,s,mid,x,y,v);
    else if(x>mid)  update(r,mid+1,e,x,y,v);
    else {
        update(l,s,mid,x,mid,v);
        update(r,mid+1,e,mid+1,y,v);
    }

    push_up(idx,l,r);
}
mask ret;

void query(int idx,int s,int e,int x,int y) {
    if( s==x && e==y ) {
        ret = ( ret | tree[idx] ) ;
        return;
    }
    int mid = (s+e)>>1 , l = (idx<<1) , r = (l|1);
    if(lazy[idx]) push_down(idx,l,r);
    if(y<=mid)      query(l,s,mid,x,y);
    else if(x>mid)  query(r,mid+1,e,x,y);
    else {
        query(l,s,mid,x,mid);
        query(r,mid+1,e,mid+1,y);
        return;
    }
}

void dfs(int u,int papa)
{
    st[u]  = ++cl;
    id[cl] = u;
    repv(i,adj[u]){
        int v = adj[u][i];
        if(v==papa) continue;
        dfs(v,u);
    }
    ed[u] = cl;
}

mask prime;

void sieve() {
    prime.set();
    for(int i=2; i<1000; i++) {
        if( prime[i] )
        for(int j=(i+i); j<1000; j+=i) {
            prime.reset(j);
        }
    }
    prime.reset(0);
    prime.reset(1);
    prime.reset(1000);
}

int main()
{
    DI(n);
    I(md);

    rep(i,1,n) {
        I(ar[i]);
        ar[i]%=md;
    }

    rep(i,1,n-1){
        DII(x,y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs(1,0);

    build(1,1,n);

    sieve();

    DI(q);

    rep(qq,1,q)
    {
        DI(cmd);

        if(cmd==1)
        {
            DII(x,v);
            v%=md;
            update(1,1,n,st[x],ed[x],v);
        }
        else
        {
            DI(x);
            ret.reset();
            query(1,1,n,st[x],ed[x]);
            int cnt = (ret&prime).count();
            PI(cnt);
        }
    }

    return 0;
}