#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 100500;
vector<int> prs;
int n, q, a[N], last[N + N];
char ft[86][17][N];
int pw[N], val[86][86];
inline void build() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)prs.size(); j++) {
      while (a[i] % prs[j] == 0) {
        ft[j][0][i]++;
        a[i] /= prs[j];
      }
    }
    if (i > 1) pw[i] = pw[i >> 1] + 1;
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i <= n - (1 << j) + 1; i++) {
      for (int k = 0; k < (int)prs.size(); k++) {
        ft[k][j][i] = max(ft[k][j - 1][i], ft[k][j - 1][i + (1 << (j - 1))]);
      }
    }
  }
  for (int i = 0; i < (int)prs.size(); i++) {
    val[i][0] = 1;
    for (int j = 1; j < 86; j++)
      val[i][j] = (val[i][j - 1] + 0ll) * prs[i] % mod;
  }
}
struct node {
  int mult;
  node *l, *r;
  node(int x) {
    mult = x;
    l = r = NULL;
  }
};
node *t[N];
void build(node *&v, int l, int r) {
  if (l == r) {
    v = new node(1);
    return;
  }
  int mid = (l + r) >> 1;
  v = new node(1);
  build(v->l, l, mid);
  build(v->r, mid + 1, r);
}
void upd(node *&v, int l, int r, int pos, int val) {
  if (l == r) {
    v = new node(val);
    return;
  }
  node *u = new node(v->mult);
  u->l = v->l;
  u->r = v->r;
  v = u;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    upd(v->l, l, mid, pos, val);
  else
    upd(v->r, mid + 1, r, pos, val);
  v->mult = (v->l->mult + 0ll) * v->r->mult % mod;
}
int get(node *v, int l, int r, int lx, int rx) {
  if (rx < l || r < lx) return 1;
  if (lx <= l && r <= rx) return v->mult;
  int mid = (l + r) >> 1;
  return (get(v->l, l, mid, lx, rx) + 0ll) * get(v->r, mid + 1, r, lx, rx) %
         mod;
}
void dfs(node *v, int l, int r) {
  if (l == r) {
    cerr << v->mult << " ";
    return;
  }
  int mid = (l + r) >> 1;
  dfs(v->l, l, mid);
  dfs(v->r, mid + 1, r);
}
inline int get(int l, int r) {
  int st = pw[r - l + 1];
  int res = 1;
  for (int i = 0; i < (int)prs.size(); i++)
    res = (res + 0ll) *
          val[i][max(ft[i][st][l], ft[i][st][r - (1 << st) + 1])] % mod;
  return res;
}
int main() {
  for (int i = 2; i * i <= (int)2e5; i++) {
    bool pr = 1;
    for (int j = 2; j * j <= i; j++)
      if (i % j == 0) pr = 0;
    if (pr) prs.push_back(i);
  }
  cerr << (int)prs.size() << "\n";
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build();
  build(t[0], 1, n);
  for (int i = 1; i <= n; i++) {
    t[i] = t[i - 1];
    if (a[i] > 1) {
      upd(t[i], 1, n, i, a[i]);
      if (last[a[i]]) upd(t[i], 1, n, last[a[i]], 1);
      last[a[i]] = i;
    }
  }
  int last = 0;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    l = (l + last) % n + 1;
    r = (r + last) % n + 1;
    if (l > r) swap(l, r);
    last = (get(t[r], 1, n, l, r) + 0ll) * get(l, r) % mod;
    printf("%d\n", last);
  }
  return 0;
}
