#include <bits/stdc++.h>
using namespace std;
const int MX = 100005;
const int INF = 1000000005;
struct WinnerTree {
  int v[MX * 4];
  int n;
  void build(int an) {
    int i;
    for (n = 1; n < an; n *= 2)
      ;
    for (i = n - 1; i > 0; i--) v[i] = 0;
  }
  void up(int i, int val) {
    i += n;
    v[i] = val;
    for (i /= 2; i; i /= 2) v[i] = max(v[i * 2], v[i * 2 + 1]);
  }
  int get(int st, int en) {
    int rlt = 0;
    st += n, en += n;
    while (st < en) {
      if (st & 1) rlt = max(rlt, v[st]);
      if (en & 1) rlt = max(rlt, v[en - 1]);
      st = (st + 1) / 2;
      en /= 2;
    }
    return rlt;
  }
};
const int mod = 1e9 + 7;
WinnerTree wt[100];
int a[MX], l[MX], r[MX], b[MX];
int expmod(int x, int y) {
  int rlt = 1;
  while (y) {
    if (y & 1) rlt = 1ll * rlt * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return rlt;
}
const int K = 350;
int sub[MX / K + 1][MX];
int nxt[MX], prv[MX];
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) scanf("%d%d", l + i, r + i);
  vector<int> primes;
  int pn = 0;
  for (int i = 2; i < 500; i++) {
    bool flag = false;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = true;
        break;
      }
    }
    if (!flag) primes.push_back(i), pn++;
  }
  for (int i = 0; i < pn; i++) {
    wt[i].build(n);
  }
  for (int i = 0; i < n; i++) {
    int x = a[i];
    for (int j = 0; j < pn; j++)
      if (a[i] % primes[j] == 0) {
        int k = 0;
        while (x % primes[j] == 0) x /= primes[j], k++;
        wt[j].up(i, k);
      }
    b[i] = x;
  }
  map<int, int> mp_last;
  for (int i = n - 1; i >= 0; i--) {
    if (mp_last.count(b[i])) {
      nxt[i] = mp_last[b[i]];
    } else
      nxt[i] = n + 1;
    mp_last[b[i]] = i;
  }
  mp_last.clear();
  for (int i = 0; i < n; i++) {
    if (mp_last.count(b[i])) {
      prv[i] = mp_last[b[i]];
    } else
      prv[i] = -1;
    mp_last[b[i]] = i;
  }
  for (int L = 0; L < n; L += K) {
    int rlt = 1;
    for (int R = L; R < n; R++) {
      if (prv[R] < L) {
        rlt = 1ll * rlt * b[R] % mod;
      }
      sub[L / K][R] = rlt;
    }
  }
  int last_ans = 0;
  for (int i = 0; i < q; i++) {
    int le, ri;
    le = (last_ans + l[i]) % n;
    ri = (last_ans + r[i]) % n;
    if (le > ri) swap(le, ri);
    int ans = 1;
    for (int k = 0; k < pn; k++) {
      ans = 1ll * ans * expmod(primes[k], wt[k].get(le, ri + 1)) % mod;
    }
    int L = ((le + K - 1) / K) * K;
    if (ri >= L) {
      ans = 1ll * ans * sub[L / K][ri] % mod;
    }
    int mid = min(ri, L - 1);
    for (int j = mid; j >= le; j--) {
      if (nxt[j] <= ri) continue;
      ans = 1ll * ans * b[j] % mod;
    }
    last_ans = ans;
    printf("%d\n", ans);
  }
  return 0;
}
