#include <bits/stdc++.h>
int vv[200000 + 1], pp[200000 + 1][6], ee[200000 + 1][6], kk[200000 + 1];
void init() {
  int a, b;
  vv[1] = 1;
  for (a = 2; a <= 200000; a++) {
    vv[a] =
        (long long)vv[a - 1000000007 % a] * (1000000007 / a + 1) % 1000000007;
    if (kk[a]) continue;
    for (b = a; b <= 200000; b += a) {
      int b_, e;
      e = 0;
      for (b_ = b; b_ % a == 0; b_ /= a) e++;
      pp[b][kk[b]] = a, ee[b][kk[b]] = e, kk[b]++;
    }
  }
}
int ll[1 + (100000 * (17 + 1) * (6 * 2 + 1))],
    rr[1 + (100000 * (17 + 1) * (6 * 2 + 1))],
    pr[1 + (100000 * (17 + 1) * (6 * 2 + 1))], _;
int update(int t, int l, int r, int i, int x) {
  int root, t_;
  root = t_ = _++;
  while (1) {
    int m;
    pr[t_] = (long long)pr[t] * x % 1000000007;
    if (r - l == 1) return root;
    m = (l + r) / 2;
    if (i < m)
      rr[t_] = rr[t], t = ll[t], t_ = ll[t_] = _++, r = m;
    else
      ll[t_] = ll[t], t = rr[t], t_ = rr[t_] = _++, l = m;
  }
}
int query(int t, int l, int r, int i) {
  int x = 1;
  while (t && r - l > 1) {
    int m = (l + r) / 2;
    if (i < m) {
      x = (long long)x * pr[rr[t]] % 1000000007;
      t = ll[t], r = m;
    } else
      t = rr[t], l = m;
  }
  x = (long long)x * pr[t] % 1000000007;
  return x;
}
int main() {
  static int st[100000], prev[200000 + 1];
  int n, q, j, t, ans;
  init();
  scanf("%d", &n);
  memset(prev, -1, sizeof prev);
  pr[0] = 1, _ = 1;
  for (j = 0, t = 0; j < n; j++) {
    int a, h;
    scanf("%d", &a);
    for (h = 0; h < kk[a]; h++) {
      int p = pp[a][h], q = 1, e = 1;
      while (e <= ee[a][h] && prev[q * p] != -1) {
        int q_ = q, i = prev[q * p];
        while (e <= ee[a][h] && prev[q * p] == i) prev[q *= p] = j, e++;
        t = update(t, 0, n, i, vv[q / q_]);
      }
      while (e <= ee[a][h]) prev[q *= p] = j, e++;
    }
    t = update(t, 0, n, j, a);
    st[j] = t;
  }
  scanf("%d", &q);
  ans = 0;
  while (q--) {
    int l, r, tmp;
    scanf("%d%d", &l, &r), l = (l + ans) % n, r = (r + ans) % n;
    if (l > r) tmp = l, l = r, r = tmp;
    printf("%d\n", (ans = query(st[r], 0, n, l)));
  }
  return 0;
}
