#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;

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;
        }
    }
}

ll po(ll x, ll n) {
    ll res = 1;
    while (n) {
        if (n % 2) {
            res *= x;
            if (res >= m) return m;
        }
        if (x >= m) return m;
        x *= x;
        n /= 2;
    }
    return res;
}

ll pp(ll x, ll k) {
    ll y = pow(x + 0.1, 1.0 / k);
    return y;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    a.resize(n);
    b.resize(n);
    for (auto& x : a) cin >> x;
    ma = *max_element(all(a));
    if (ma == 1) {
        trivial();
        return 0;
    }
    cin >> q;
    while (q--) {
        ll t; cin >> t;
        if (t == 1) {
            ll k; cin >> k;
            ma = *max_element(all(a));
            if (po(ma, k) < m) {
                for (auto& x : a)
                    x = po(x, k);
            }
        }
        else if (t == 2) {
            ll k; cin >> k;
            for (int i = 0; i < n; ++i)
                b[i] = pp(a[i], k);
            bool go = true;
            for (int i = 0; go && i < n; ++i)
                if (po(b[i], k) != a[i])
                    go = false;
            if (go)
                a = b;
        }
        else {
            ll l, r; cin >> l >> r; --l; --r;
            ll res = 0;
            for (int i = l; i <= r; ++i)
                res += a[i];
            cout << res << "\n";
        }
    }

    return 0;
}
