#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define ll  long long
#define vi  vector<ll >
#define vvi vector<vi >
#define all(x) x.begin(), x.end()

ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }

ll m = 100001;
ll n, q, ma;
vi a, b[17], osn, ste;

void trivial() {
    cin >> q;
    while (q--) {
        ll t; cin >> t;
        if (t < 3) {
            ll k; cin >> k;
        }
        else {
            ll l, r; cin >> l >> r; --l; --r;
            cout << r - l + 1 << endl;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    osn.resize(m); iota(all(osn), 0);
    ste.assign(m, 1); ste[1] = 0;
    for (ll x = 2; x * x < m; ++x) {
        ll k = 2;
        ll z = x * x;
        for (; z < m; z *= x, ++k) {
            if (ste[z] < k) {
                ste[z] = k;
                osn[z] = x;
            }
        }
    }
    cin >> n;
    a.resize(n);
    for (auto& x : a) cin >> x;
    ma = *max_element(all(a));
    if (ma == 1) {
        trivial();
        return 0;
    }
    ll k_cur = ste[ma];
    for (auto x : a)
        k_cur = gcd(k_cur, ste[x]);
    b[1] = a;
    if (k_cur > 1) {
        for (ll i = 0; i < n; ++i)
            b[1][i] = pow(a[i] + 0.1, 1.0 / k_cur);
    }
    ma = *max_element(all(b[1]));
    ll k_max = 1;
    ll val = ma;
    while (val * ma < m) {
        val *= ma;
        ++k_max; b[k_max] = a;
    }
    for (ll i = 0; i < n; ++i)
        for (ll c = 2; c <= k_max; ++c)
            b[c][i] = b[c - 1][i] * b[1][i];
    for (ll c = 1; c <= k_max; ++c)
        for (ll i = 1; i < n; ++i)
            b[c][i] += b[c][i - 1];

    cin >> q;
    while (q--) {
        ll t; cin >> t;
        if (t == 1) {
            ll k; cin >> k;
            if (k_cur * k <= k_max)
                k_cur *= k;
        }
        else if (t == 2) {
            ll k; cin >> k;
            if (k_cur % k == 0)
                k_cur /= k;
        }
        else {
            ll l, r; cin >> l >> r; --l; --r;
            ll res = b[k_cur][r];
            if (l > 0) res -= b[k_cur][l - 1];
            cout << res << endl;
        }
    }

    return 0;
}
