#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<int> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            st[i].resize(lg+1);
            inv[i].resize(lg+1);
            for (int& j: st[i]) j = 0;
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(480e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    for (int i = 1; i < SZ(st[p]); i++) {
        auto& ps = st[p][i];
        if (!ps) {
            if (i == cnt) ps = i;
            continue;
        }
        if (i <= cnt) root = update(root, 1, n, ps, inv[p][i]); //cout <<x<<":"<< ps << " /" << p << " " << i << "\n";
        else root = update(root, 1, n, ps, inv[p][cnt]); //cout <<x<<":"<< ps << " /" << p << " " << cnt << "\n";
        ps = 0;
        st[p][i-cnt] = ps;
    }
    st[p][cnt] = x;
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    //for (int j = 1; j <= 10; j++)
    //    if (st[2][j]) cout << st[2][j] << ":" << j << " ";cout << endl;
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l = (last + l) % n + 1;
        r = (last + r) % n + 1;
        if (l > r) swap(l, r);
        //cout << l << " " << r << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
int inv[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            inv[i] = qpow(i, M - 2);
        }
    }
}

int n, q, tot;
vector<pii> st[N];
struct Node {
    int lc, rc, val;
} node[static_cast<int>(480e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int i, int p, int cnt) {
    for (auto& pc: st[p]) {
        int pos = pc.fi, ct = pc.se;
        int iv = 1;
        if (ct <= cnt) {
            for (int j = 0; j < ct; j++)
                iv = 1ll * iv * inv[p] % M;
            pc.se = 0;
        } else {
            for (int j = 0; j < cnt; j++)
                iv = 1ll * iv * inv[p] % M;
            pc.se = ct - cnt;
        }
        root = update(root, 1, n, pos, iv);
    }
    st[p].emplace_back(i, cnt);
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, i, val);
}
int append(int i, int x) {
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l = (last + l) % n + 1;
        r = (last + r) % n + 1;
        if (l > r) swap(l, r);
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<pii> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            inv[i].resize(lg+1);
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    int left = cnt;
    while (!st[p].empty() && left) {
        auto pr = st[p].back();
        st[p].pop_back();
        if (left < pr.se) {
            root = update(root, 1, n, pr.fi, inv[p][left]);
            st[p].emplace_back(pr.fi, pr.se - left), left = 0;
        } else {
            root = update(root, 1, n, pr.fi, inv[p][pr.se]);
            left -= pr.se;
        }
    }
    st[p].emplace_back(x, cnt);
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l = (last + l) % n + 1;
        r = (last + r) % n + 1;
        if (l > r) swap(l, r);
        //cout << l << " " << r << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<int> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            st[i].resize(lg+1);
            inv[i].resize(lg+1);
            for (int& j: st[i]) j = 0;
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    for (int i = 1; i < SZ(st[p]); i++) {
        auto& ps = st[p][i];
        if (!ps) {
            if (i == cnt) ps = i;
            continue;
        }
        if (i <= cnt) root = update(root, 1, n, ps, inv[p][i]); //cout <<x<<":"<< ps << " /" << p << " " << i << "\n";
        else root = update(root, 1, n, ps, inv[p][cnt]); //cout <<x<<":"<< ps << " /" << p << " " << cnt << "\n";
        ps = 0;
        st[p][i-cnt] = ps;
    }
    st[p][cnt] = x;
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    //for (int j = 1; j <= 10; j++)
    //    if (st[2][j]) cout << st[2][j] << ":" << j << " ";cout << endl;
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l = (last + l) % n + 1;
        r = (last + r) % n + 1;
        if (l > r) swap(l, r);
        //cout << l << " " << r << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<int> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            st[i].resize(lg+1);
            inv[i].resize(lg+1);
            for (int& j: st[i]) j = 0;
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    for (int i = 1; i < SZ(st[p]); i++) {
        auto& ps = st[p][i];
        if (!ps) {
            if (i == cnt) ps = i;
            continue;
        }
        if (i <= cnt) root = update(root, 1, n, ps, inv[p][i]); //cout <<x<<":"<< ps << " /" << p << " " << i << "\n";
        else root = update(root, 1, n, ps, inv[p][cnt]); //cout <<x<<":"<< ps << " /" << p << " " << cnt << "\n";
        ps = 0;
        if (i > cnt) st[p][i-cnt] = ps;
    }
    st[p][cnt] = x;
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    //for (int j = 1; j <= 10; j++)
    //    if (st[2][j]) cout << st[2][j] << ":" << j << " ";cout << endl;
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l = (last + l) % n + 1;
        r = (last + r) % n + 1;
        if (l > r) swap(l, r);
        //cout << l << " " << r << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int pref[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	map<int, int> lst_val, lst_index;
	scanf("%d", &n);
	pref[0] = 1;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		pref[i] = pref[i - 1];
		T[i] = T[i - 1];
		for(auto [p, e] : factor(x)){
			int d = max(e - lst_val[p], 0);
			e -= d;
			pref[i] = mul(pref[i], powmod(p, d));
			T[i] = update(T[i], 0, n, lst_index[p] + 1, powmod(p, e));
			lst_index[p] = i;
		}
	}
}

int solve(int l, int r){
	int ret = mul(pref[r], inv(pref[l - 1]));
	ret = mul(ret, query(T[r], 0, n, 0, l-1));
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int pref[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	map<int, int> lst_val, lst_index;
	scanf("%d", &n);
	pref[0] = 1;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		pref[i] = pref[i - 1];
		T[i] = T[i - 1];
		for(auto [p, e0] : factor(x)){
			int d = max(e0 - lst_val[p], 0);
			int e = e0 - d;
			int pd = powmod(p, abs(d)), pe = powmod(p, abs(e));
			if(d < 0) pd = inv(pd);
			if(e < 0) pe = inv(pe);
//			if(p == 2) cerr << i << ": " << p << "^" << e0 << " -> " << pd << " " << pe << endl;
			pref[i] = mul(pref[i], pd);
			T[i] = update(T[i], 0, n, lst_index[p], pe);
			lst_index[p] = i;
			lst_val[p] = e0;
		}
	}
}

int solve(int l, int r){
	int ret = mul(pref[r], inv(pref[l - 1]));
	int A = query(T[r], 0, n, 0, l-1);
	int B = query(T[l-1], 0, n, 0, l-1);
	//cerr << l << " " << r << " " << ret << " * " << A << "/" << B << endl;
	ret = mul(ret, A);
	ret = mul(ret, inv(B));
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int pref[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	map<int, int> lst_val, lst_index;
	scanf("%d", &n);
	pref[0] = 1;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		pref[i] = pref[i - 1];
		T[i] = T[i - 1];
		for(auto [p, e0] : factor(x)){
			int d = max(e0 - lst_val[p], 0);
			int e = e0 - d;
			int pd = powmod(p, d), pe = powmod(p, e);
			pref[i] = mul(pref[i], pd);
			T[i] = update(T[i], 0, n, lst_index[p], pe);
			lst_index[p] = i;
			lst_val[p] += d;
		}
	}
}

int solve(int l, int r){
	int ret = mul(pref[r], inv(pref[l - 1]));
	int A = query(T[r], 0, n, 0, l-1);
	int B = query(T[l-1], 0, n, 0, l-1);
//	cerr << l << " " << r << " " << ret << " * " << A << "/" << B << endl;
	ret = mul(ret, A);
	ret = mul(ret, inv(B));
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	scanf("%d", &n);
	map<int, vp> lst;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		T[i] = T[i - 1];
		map<int, int> aux;
		for(auto [p, e] : factor(x)){
			vp & ST = lst[p];
			int e0 = 0;
			while(!ST.empty() && ST.back().second < e){
				int s = inv(powmod(p, ST.back().second - e0));
				int k = ST.back().first;
				if(!aux.count(k)) aux[k] = 1;
				aux[k] = mul(aux[k], s);
				e0 = ST.back().second;
				ST.pop_back();
			}
			if(!ST.empty()){
				int old = ST.back().second - e0;
				int target = ST.back().second - e;
				int s = inv(powmod(p, old - target));
				int k = ST.back().first;
				if(!aux.count(k)) aux[k] = 1;
				aux[k] = mul(aux[k], s);
			}
			if(!aux.count(i)) aux[i] = 1;
			aux[i] = mul(aux[i], powmod(p, e));
			ST.emplace_back(i, e);
		}
		for(auto [k, s] : aux)
			T[i] = update(T[i], 1, n, k, s);
	}
}

int solve(int l, int r){
	return query(T[r], 1, n, l, r);
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int pref[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	map<int, int> lst_val, lst_index;
	scanf("%d", &n);
	pref[0] = 1;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		pref[i] = pref[i - 1];
		T[i] = T[i - 1];
		for(auto [p, e] : factor(x)){
			int d = max(e - lst_val[p], 0);
			e -= d;
			pref[i] = mul(pref[i], powmod(p, d));
			T[i] = update(T[i], 0, n, lst_index[p] + 1, powmod(p, e));
			lst_index[p] = i;
		}
	}
}

int solve(int l, int r){
	int ret = mul(pref[r], inv(pref[l - 1]));
	ret = mul(ret, query(T[r], 0, n, 0, l-1));
	ret = mul(ret, inv(query(T[l-1], 0, n, 0, l-1)));
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int pref[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	map<int, int> lst_val, lst_index;
	scanf("%d", &n);
	pref[0] = 1;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		pref[i] = pref[i - 1];
		T[i] = T[i - 1];
		for(auto [p, e0] : factor(x)){
			int d = e0 - lst_val[p];
			int e = e0 - d;
			int pd = powmod(p, abs(d)), pe = powmod(p, abs(e));
			if(d < 0) pd = inv(pd);
			if(e < 0) pe = inv(pe);
			pref[i] = mul(pref[i], pd);
			T[i] = update(T[i], 0, n, lst_index[p], pe);
			lst_index[p] = i;
			lst_val[p] = e0;
		}
	}
}

int solve(int l, int r){
	int ret = mul(pref[r], inv(pref[l - 1]));
	int A = query(T[r], 0, n, 0, l-1);
	int B = query(T[l-1], 0, n, 0, l-1);
//	cerr << l << " " << r << " " << ret << " * " << A << "/" << B << endl;
	ret = mul(ret, A);
	ret = mul(ret, inv(B));
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

const int mod = 1e9 + 7, MAXN = 100*1000 + 10, MAXA = 200*1000 + 10;
int mul(int a, int b){
	return (a*(ll)b)%mod;
}
int powmod(int x, int p){
	if(!p) return 1;
	int y = 1;
	for(; p > 1; p >>= 1){
		if(p&1) y = mul(x, y);
		x = mul(x, x);
	}
	return mul(x, y);
}
int inv(int x){
	if(x == 1) return 1;
	return powmod(x, mod - 2);
}

struct node {
	node *l, *r;
	int val;
	node(){l = r = 0; val = 1;}
};

node *T[MAXN];
int prime[MAXA];
int n;

void sieve(){
	for(int i = 2; i < MAXA; i++){
		if(prime[i]) continue;
		prime[i] = i;
		for(ll j = i*(ll)i; j < MAXA; j += i)
			prime[j] = i;
	}
}

vp factor(int x){
	vp F;
	while(x > 1){
		int p = prime[x];
		int e = 0;
		while(x%p == 0) {
			x /= p;
			e++;
		}
		F.emplace_back(p, e);
	}
	return F;
}

node* update(node *root, int s, int e, int p, int v){
	node *ret = new node();
	if(root) *ret = *root;
	ret->val = mul(ret->val, v);
	if(s == e) return ret;
	int m = (s + e) >> 1;
	if(p <= m) ret->l = update(ret->l, s, m, p, v);
	else ret->r = update(ret->r, m+1, e, p, v);
	return ret;
}

int query(node *root, int s, int e, int l, int r){
	if(!root) return 1;
	if(l <= s && e <= r) return root->val;
	int m = (s + e) >> 1;
	if(r <= m) return query(root->l, s, m, l, r);
	if(m < l) return query(root->r, m+1, e, l, r);
	return mul(query(root->l, s, m, l, m), query(root->r, m+1, e, m+1, r));
}

void read(){
	scanf("%d", &n);
	map<int, vp> lst;
	for(int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		T[i] = T[i - 1];
		for(auto [p, e] : factor(x)){
			vp & ST = lst[p];
			int e0 = 0;
			while(!ST.empty() && ST.back().second < e){
				int s = inv(powmod(p, ST.back().second - e0));
				T[i] = update(T[i], 1, n, ST.back().first, s);
				e0 = ST.back().second;
				ST.pop_back();
			}
			if(!ST.empty()){
				int old = ST.back().second - e0;
				int target = ST.back().second - e;
				int s = inv(powmod(p, old - target));
				T[i] = update(T[i], 1, n, ST.back().first, s);
			}
			T[i] = update(T[i], 1, n, i, powmod(p, e));
			ST.emplace_back(i, e);
		}
	}
}

int solve(int l, int r){
	return query(T[r], 1, n, l, r);
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	sieve();
	read();
	int ans = 0; int m; scanf("%d", &m);
	while(m--){
		int l, r; scanf("%d %d", &l, &r);
		l = (l + ans)%n + 1;
		r = (r + ans)%n + 1;
		if(l > r) swap(l, r);
		ans = solve(l, r);
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
const int L = 18;
int nx[87][MAXN];
int t2[87][4*MAXN];
int a[MAXN];
bool isp[455];
int name[455];
int last[MAXN];
pii par[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[4*MAXN];
vector<int> pre[4*MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

void ot(int v, int l, int r, int hg){
    if(l == r){
        t2[hg][v] = nx[hg][l];
    }else{
        int m = (l + r) / 2;
        ot(2*v, l, m, hg);
        ot(2*v+1, m + 1, r, hg);
        t2[hg][v] = max(t2[hg][2*v], t2[hg][2*v+1]);
    }

}
int q2(int v, int tl, int tr, int l, int r, int hg){
    if(l > r) return 0;
    if(tl == l && tr == r){
        return t2[hg][v];
    }else{
        int tm = (tl + tr) / 2;
        return max(q2(2*v, tl, tm, l, min(r, tm), hg), q2(2*v + 1, tm + 1, tr, max(tm + 1, l), r, hg));
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }
    cerr<<p.size()<<endl;
    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                if(j < 450){
                    nx[name[j]][i]++;
                }
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    for(int i = 0; i < p.size(); i++)
    ot(1, 0, n - 1, i);

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        int len = r - l + 1;
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        for(int i = 0; i < (int) p.size(); i++){
            int x = q2(1, 0, n - 1, l, r, i);
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl<<flush;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
const int L = 18;
int nx[87][MAXN];
int t2[87][4*MAXN];
int a[MAXN];
bool isp[455];
int name[455];
int last[MAXN];
pii par[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[4*MAXN];
vector<int> pre[4*MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

void ot(int v, int l, int r){
    if(l == r){
        for(int i = 0; i < 87; i++)
            t2[i][v] = nx[i][l];
    }else{
        int m = (l + r) / 2;
        ot(2*v, l, m);
        ot(2*v+1, m + 1, r);
        for(int i = 0; i < 87; i++)
            t2[i][v] = max(t2[i][2*v], t2[i][2*v+1]);
    }

}
void q2(int v, int tl, int tr, int l, int r, vector<int> & h){
    if(l > r) return ;
    if(tl == l && tr == r){
        for(int i = 0; i < h.size(); i++)
            h[i] = max(h[i], t2[i][v]);
    }else{
        int tm = (tl + tr) / 2;
        q2(2*v, tl, tm, l, min(r, tm), h);
        q2(2*v + 1, tm + 1, tr, max(tm + 1, l), r, h);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }
    cerr<<p.size()<<endl;
    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                if(j < 450){
                    nx[name[j]][i]++;
                }
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    ot(1, 0, n - 1);

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        int len = r - l + 1;
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        vector<int> an;
        an.resize(87, 0);
        q2(1, 0, n - 1, l, r, an);
        for(int i = 0; i < (int) p.size(); i++){
            int x = an[i];
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
const int L = 18;
int nx[87][MAXN][L];
int a[MAXN];
bool isp[455];
int name[455];
int last[MAXN];
pii par[MAXN];
int lg[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[4*MAXN];
vector<int> pre[4*MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }
    cerr<<p.size()<<endl;
    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                if(j < 450){
                    nx[name[j]][i][0]++;
                }
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i][0]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    //cerr<<"kontrol"<<endl;
    lg[1] = 0;
    for(int i = 2; i <= n; i++){
        lg[i] = lg[i / 2] + 1;
    }

    for(int j = 0; j < p.size(); j++)
        for(int i = 1; i < L; i++){
            for(int k = 0; k < n; k++){
                if(k + (1<<(i - 1)) >= n) continue;
                nx[j][k][i] = max(nx[j][k][i - 1], nx[j][k + (1<<(i - 1))][i - 1]);
            }
        }

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        int len = r - l + 1;
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        int ln = lg[len];
        for(int i = 0; i < (int) p.size(); i++){
            int x = max(nx[i][l][ln], nx[i][r - (1<<ln) + 1][ln]);
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl<<flush;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
const int L = 18;
int nx[87][MAXN];
int t2[87][4*MAXN];
int a[MAXN];
bool isp[455];
int name[455];
int last[MAXN];
pii par[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[4*MAXN];
vector<int> pre[4*MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

void ot(int v, int l, int r, int hg){
    if(l == r){
        t2[hg][v] = nx[hg][l];
    }else{
        int m = (l + r) / 2;
        ot(2*v, l, m, hg);
        ot(2*v+1, m + 1, r, hg);
        t2[hg][v] = max(t2[hg][2*v], t2[hg][2*v+1]);
    }

}
int q2(int v, int tl, int tr, int l, int r, int hg){
    if(l > r) return 0;
    if(tl == l && tr == r){
        return t2[hg][v];
    }else{
        int tm = (tl + tr) / 2;
        return max(q2(2*v, tl, tm, l, min(r, tm), hg), q2(2*v + 1, tm + 1, tr, max(tm + 1, l), r, hg));
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }
    cerr<<p.size()<<endl;
    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                if(j < 450){
                    nx[name[j]][i]++;
                }
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    for(int i = 0; i < p.size(); i++)
        ot(1, 0, n - 1, i);

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        int len = r - l + 1;
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        for(int i = 0; i < (int) p.size(); i++){
            int x = q2(1, 0, n - 1, l, r, i);
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
int nx[87][MAXN];
int t2[87][4*MAXN];
int a[MAXN];
bool isp[455];
int name[455];
int last[2*MAXN];
pii par[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[4*MAXN];
vector<int> pre[4*MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

void ot(int v, int l, int r){
    if(l == r){
        for(int i = 0; i < 87; i++)
            t2[i][v] = nx[i][l];
    }else{
        int m = (l + r) / 2;
        ot(2*v, l, m);
        ot(2*v+1, m + 1, r);
        for(int i = 0; i < 87; i++)
            t2[i][v] = max(t2[i][2*v], t2[i][2*v+1]);
    }

}
void q2(int v, int tl, int tr, int l, int r, vector<int> & h){
    if(l > r) return ;
    if(tl == l && tr == r){
        for(int i = 0; i < (int) h.size(); i++)
            h[i] = max(h[i], t2[i][v]);
    }else{
        int tm = (tl + tr) / 2;
        q2(2*v, tl, tm, l, min(r, tm), h);
        q2(2*v + 1, tm + 1, tr, max(tm + 1, l), r, h);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }

    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                nx[name[j]][i]++;
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    ot(1, 0, n - 1);

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        vector<int> an(87, 0);
        q2(1, 0, n - 1, l, r, an);
        for(int i = 0; i < (int) p.size(); i++){
            int x = an[i];
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
const int L = 18;
int nx[100][MAXN][L];
int a[MAXN];
bool isp[MAXN];
int name[455];
int last[3*MAXN];
pii par[3*MAXN];
int lg[MAXN];
ll bp(ll as, ll b){
    ll res = 1;
    while(b){
        if(b % 2)
            res = (res * as) % mod;
        as = (as * as)%mod;
        b = b / 2;
    }
    return res;
}

vector<pii> t[MAXN];
vector<int> pre[MAXN];
void build(int v, int l, int r){
    if(l == r){
        if(par[l].ss == -1) return;
        t[v].push_back(par[l]);
        pre[v].push_back(par[l].ss);
    }else{
        int m = (l + r) / 2;
        build(2*v, l, m);
        build(2*v + 1, m + 1, r);
        t[v] = t[2*v];
        for(pii &u: t[2*v + 1])
            t[v].push_back(u);
        sort(t[v].begin(), t[v].end());
        //cerr<<"kon 1"<<endl;
        for(int i = 0; i < (int)t[v].size(); i++){
            if(i)
                pre[v].push_back(1LL * pre[v][i - 1] * t[v][i].ss % mod);
            else
                pre[v].push_back(t[v][i].ss);
        }
       // cerr<<"kon 2"<<endl;
    }
}

int que(int v, int tl, int tr, int l, int r, int fl){
    if(l > r) return 1;
    if(tl == l && tr == r){
        if(t[v].empty()) return 1;
        int idx = lower_bound(t[v].begin(), t[v].end(), make_pair(fl - 1, mod)) - t[v].begin();
        if(idx == 0) return 1;
        else idx--;
        return pre[v][idx];
    }else{
        int tm = (tl + tr) / 2;
        return 1LL * que(2*v, tl, tm, l, min(tm, r), fl) * que(2*v + 1, tm + 1, tr, max(tm + 1, l), r, fl) % mod;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    vector<int> p;
    for(int i = 2; i < 450; i++){
        if(isp[i]) continue;
        p.push_back(i);
        for(int j = i*i; j < 450; j+=i)
            isp[j] = 1;
    }
    for(int i = 0; i < (int) p.size(); i++){
        name[p[i]] = i;
    }
    memset(last, -1, sizeof(last));

    cin>>n;

    for(int i = 0; i < n; i++){
        par[i] = {-1, -1};
        cin>>a[i];
        int c = a[i];
        for(int j = 2; j * j <= c; j++){
            while(c % j == 0){
                if(j < 450){
                    nx[name[j]][i][0]++;
                }
                c /= j;
            }
        }
        if(c != 1){
            if(c < 450){
                nx[name[c]][i][0]++;
            }else{
                par[i] = {last[c], c};
                last[c] = i;
            }
        }
    }
    build(1, 0, n - 1);
    //cerr<<"kontrol"<<endl;
    lg[1] = 0;
    for(int i = 2; i <= n; i++){
        lg[i] = lg[i / 2] + 1;
    }

    for(int j = 0; j < 100; j++)
        for(int i = 1; i < L; i++){
            for(int k = 0; k < n; k++){
                if(k + (1<<(i - 1)) >= n) continue;
                nx[j][k][i] = max(nx[j][k][i - 1], nx[j][k + (1<<(i - 1))][i - 1]);
            }
        }

    int q;
    cin>>q;
    int lst = 0;

    while(q--){
        int l, r;
        cin>>l>>r;
        l = (l + lst) % n;
        r = (r + lst) % n;
        if(l > r) swap(l, r);
        int len = r - l + 1;
        //cerr<<l<<" "<<r<<endl;
        int ans = 1;
        int ln = lg[len];
        for(int i = 0; i < (int) p.size(); i++){
            int x = max(nx[i][l][ln], nx[i][r - (1<<ln) + 1][ln]);
            //if(x)
                //cerr<<p[i]<<" "<<i<<" "<<x<<endl;
            ans = 1LL * ans * bp(p[i], x) % mod;
        }
        //cerr<<endl<<ans<<endl;

        ans = 1LL * ans * que(1, 0, n - 1, l, r, l) % mod;

        cout<<(lst = ans)<<endl<<flush;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

inline void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i * i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[88][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) >> 1;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st >> 1);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    node *l, *r;
    int pr;
    node() {
        pr = 1;
        l = r = nullptr;
    }
    node(node *old) {
        if (!old) {
            pr = 1;
            l = r = nullptr;
        }
        else {
            l = old->l;
            r = old->r;
            pr = old->pr;
        }
    }
};

node *root = new node();

node* pt[100000 + 50];

int lst[200000 + 50];

void make_mult(node *v, int tl, int tr, int pos, int val) {
    if (val == 1)
        return;
    while(true) {
        v->pr = get_prod(v->pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            v->l = new node(v->l);
            tr = tm;
            v = v->l;
        }
        else {
            v->r = new node(v->r);
            tl = tm + 1;
            v = v->r;
        }
    }
}
int get_mult(node *v, int tl, int tr, int l, int r) {
    if (!v || v->pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return v->pr;
    int tm = (tl + tr) >> 1;
    return get_prod(get_mult(v->l, tl, tm, l, r), get_mult(v->r, tm + 1, tr, l, r));
}

inline void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    pt[n] = root;
    for (int i = n - 1; i >= 0; i--) {
        pt[i] = new node(pt[i + 1]);
        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < o; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

inline void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i * i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[88][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) >> 1;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st >> 1);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    int l, r;
    int pr;
    node() {
        pr = 1;
        l = r = -1 + 200000 + 50;
    }
};

node nodes[200000 * 20];
int nd = 1;

int pt[100000 + 50];

int lst[200000 + 50];

void make_mult(int v, int tl, int tr, int pos, int val) {
    if (val == 1)
        return;
    while(true) {
        nodes[v].pr = get_prod(nodes[v].pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            nodes[nd] = nodes[nodes[v].l];
            nodes[v].l = nd;
            nd++;

            tr = tm;
            v = nodes[v].l;
        }
        else {
            nodes[nd] = nodes[nodes[v].r];
            nodes[v].r = nd;
            nd++;

            tl = tm + 1;
            v = nodes[v].r;
        }
    }
}
int get_mult(int v, int tl, int tr, int l, int r) {
    if (v == 200000 + 50 - 1 || nodes[v].pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return nodes[v].pr;
    int tm = (tl + tr) >> 1;
    return get_prod(get_mult(nodes[v].l, tl, tm, l, r), get_mult(nodes[v].r, tm + 1, tr, l, r));
}

inline void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    for (int i = n - 1; i >= 0; i--) {
        nodes[nd] = nodes[pt[i + 1]];
        pt[i] = nd;
        nd++;

        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < o; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i + i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[87][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) / 2;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st / 2);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    node *l, *r;
    int pr;
    node() {
        pr = 1;
        l = r = nullptr;
    }
    node(node *old) {
        if (!old) {
            pr = 1;
            l = r = nullptr;
        }
        else {
            l = old->l;
            r = old->r;
            pr = old->pr;
        }
    }
};

node *root = new node();

node* pt[100000 + 50];

int lst[200000 + 50];

void make_mult(node *v, int tl, int tr, int pos, int val) {
    while(true) {
        v->pr = get_prod(v->pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            v->l = new node(v->l);
            tr = tm;
        }
        else {
            v->r = new node(v->r);
            tl = tm + 1;
        }
    }
}
int get_mult(node *v, int tl, int tr, int l, int r) {
    if (!v || v->pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return v->pr;
    int tm = (tl + tr) / 2;
    return get_prod(get_mult(v->l, tl, tm, l, r), get_mult(v->r, tm + 1, tr, l, r));
}

void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    pt[n] = root;
    for (int i = n - 1; i >= 0; i--) {
        pt[i] = new node(pt[i + 1]);
        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < 3; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

inline void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i * i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[88][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) >> 1;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st >> 1);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    int l, r;
    int pr;
    node() {
        pr = 1;
        l = r = -1 + 200000 * 40;
    }
};

node nodes[200000 * 40];
int nd = 1;

int pt[100000 + 50];

int lst[200000 + 50];

void make_mult(int v, int tl, int tr, int pos, int val) {
    if (val == 1)
        return;
    while(true) {
        nodes[v].pr = get_prod(nodes[v].pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            nodes[nd] = nodes[nodes[v].l];
            nodes[v].l = nd;
            nd++;

            tr = tm;
            v = nodes[v].l;
        }
        else {
            nodes[nd] = nodes[nodes[v].r];
            nodes[v].r = nd;
            nd++;

            tl = tm + 1;
            v = nodes[v].r;
        }
    }
}
int get_mult(int v, int tl, int tr, int l, int r) {
    if (v == 200000 + 50 - 1 || nodes[v].pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return nodes[v].pr;
    int tm = (tl + tr) >> 1;
    return get_prod(get_mult(nodes[v].l, tl, tm, l, r), get_mult(nodes[v].r, tm + 1, tr, l, r));
}

inline void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    for (int i = n - 1; i >= 0; i--) {
        nodes[nd] = nodes[pt[i + 1]];
        pt[i] = nd;
        nd++;

        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < o; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

inline void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i * i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[88][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) >> 1;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st >> 1);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    int l, r;
    int pr;
    node() {
        pr = 1;
        l = r = -1 + 200000 * 40;
    }
};

node nodes[200000 * 40];
int nd = 1;

int pt[100000 + 50];

int lst[200000 + 50];

void make_mult(int v, int tl, int tr, int pos, int val) {
    if (val == 1)
        return;
    while(true) {
        nodes[v].pr = get_prod(nodes[v].pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            nodes[nd] = nodes[nodes[v].l];
            nodes[v].l = nd;
            nd++;

            tr = tm;
            v = nodes[v].l;
        }
        else {
            nodes[nd] = nodes[nodes[v].r];
            nodes[v].r = nd;
            nd++;

            tl = tm + 1;
            v = nodes[v].r;
        }
    }
}
int get_mult(int v, int tl, int tr, int l, int r) {
    if (v == 200000 * 40 - 1 || nodes[v].pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return nodes[v].pr;
    int tm = (tl + tr) >> 1;
    return get_prod(get_mult(nodes[v].l, tl, tm, l, r), get_mult(nodes[v].r, tm + 1, tr, l, r));
}

inline void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    for (int i = n - 1; i >= 0; i--) {
        nodes[nd] = nodes[pt[i + 1]];
        pt[i] = nd;
        nd++;

        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < o; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define pii pair<int, int>

const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;

using namespace std;
using namespace __gnu_pbds;

bool valid(int x, int y, int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int p[89], val[89][100005];
int a[100000 + 5];
int o = 0;
bool ne_prost[200000 + 50];

inline void init() {
    for (int i = 2; i * i <= 200050; i++) {
        if (!ne_prost[i]) {
            p[o] = i;
            o++;
            for (int j = i * i; j < 200000 + 5; j += i) {
                ne_prost[j] = true;
            }
        }
    }
}

int t[88][4 * 100000 + 5];

int n, q, ans;

void build(int v, int tl, int tr, int num) {
    if (tl == tr) {
        t[num][v] = val[num][tl];
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, num);
    build(v * 2 + 1, tm + 1, tr, num);

    t[num][v] = max(t[num][v * 2], t[num][v * 2 + 1]);
}

int getMax(int v, int tl, int tr, int l, int r, int num) {
    if (t[num][v] == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r) {
        return t[num][v];
    }

    int tm = (tl + tr) >> 1;
    return max(getMax(v * 2, tl, tm, l, r, num), getMax(v * 2 + 1, tm + 1, tr, l, r, num));
}

inline int get_prod(int a, int b) {
    return ((ll)a * (ll)b) % mod;
}
int bin_pow(int num, int st) {
    if (st == 0)
        return 1;
    if (st % 2 == 1)
        return get_prod(bin_pow(num, st - 1), num);
    else {
        int qz = bin_pow(num, st >> 1);
        return get_prod(qz, qz);
    }
}
inline int inv(int x) {
    return bin_pow(x, mod - 2);
}

struct node {
    int l, r;
    int pr;
    node() {
        pr = 1;
        l = r = -1 + 200000 + 50;
    }
};

node nodes[200000 + 50];
int nd = 1;

int pt[100000 + 50];

int lst[200000 + 50];

void make_mult(int v, int tl, int tr, int pos, int val) {
    if (val == 1)
        return;
    while(true) {
        nodes[v].pr = get_prod(nodes[v].pr, val);
        if (tl == tr)
            break;

        int tm = (tl + tr) / 2;
        if (pos <= tm) {
            nodes[nd] = nodes[nodes[v].l];
            nodes[v].l = nd;
            nd++;

            tr = tm;
            v = nodes[v].l;
        }
        else {
            nodes[nd] = nodes[nodes[v].r];
            nodes[v].r = nd;
            nd++;

            tl = tm + 1;
            v = nodes[v].r;
        }
    }
}
int get_mult(int v, int tl, int tr, int l, int r) {
    if (v == 200000 + 50 - 1 || nodes[v].pr == 1 || tl > r || tr < l)
        return 1;
    if (tl >= l && tr <= r)
        return nodes[v].pr;
    int tm = (tl + tr) >> 1;
    return get_prod(get_mult(nodes[v].l, tl, tm, l, r), get_mult(nodes[v].r, tm + 1, tr, l, r));
}

inline void omg_pre_calc() {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < o; j++) {
            val[j][i] = 1;
            while(a[i] % p[j] == 0) {
                a[i] /= p[j];
                val[j][i] *= p[j];
            }
        }
    }

    for (int j = 0; j < o; j++) {
        build(1, 0, n - 1, j);
    }
}

signed main() {
    fast_io;

    init();

    cin >> n;
    omg_pre_calc();

    for (int i = n - 1; i >= 0; i--) {
        nodes[nd] = nodes[pt[i + 1]];
        pt[i] = nd;
        nd++;

        if (lst[a[i]] != 0) {
            make_mult(pt[i], 0, n - 1, lst[a[i]], inv(a[i]));
        }
        make_mult(pt[i], 0, n - 1, i, a[i]);
        lst[a[i]] = i;
    }

    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x += ans;
        y += ans;
        x %= n;
        y %= n;

        if (x > y)
            swap(x, y);

        ans = 1;
        for (int j = 0; j < o; j++) {
            ans = get_prod(ans, getMax(1, 0, n - 1, x, y, j));
        }

        ans = get_prod(ans, get_mult(pt[x], 0, n - 1, x, y));

        cout << ans << endl;
    }

    return 0;
}