#include <bits/stdc++.h>
using namespace std;
int INF = 1e9 + 7;
long long LLINF = 1e18;
long long MOD = 1e9 + 7;
ostream& operator<<(ostream& out, vector<int>& v) {
  for (int num : v) out << num << ' ';
  return out;
}
ostream& operator<<(ostream& out, vector<long long>& v) {
  for (long long num : v) out << num << ' ';
  return out;
}
istream& operator>>(istream& in, vector<int>& v) {
  for (int i = 0; i < v.size(); i++) in >> v[i];
  return in;
}
istream& operator>>(istream& in, vector<long long>& v) {
  for (int i = 0; i < v.size(); i++) in >> v[i];
  return in;
}
int eu(int a, int b) {
  if (a > b) swap(a, b);
  if (a == 0)
    return b;
  else
    return eu(b % a, a);
}
unsigned long long binpow(unsigned long long a, unsigned long long pow) {
  unsigned long long cur = a;
  unsigned long long ans = 1;
  for (; pow > 0; pow >>= 1) {
    if (pow & 1) ans *= cur;
    ans %= INF;
    cur *= cur;
    cur %= INF;
  }
  return ans;
}
int root(long double num, int pow) {
  long long ans = 0;
  for (; binpow(ans + 1, pow) <= num; ans++)
    ;
  return ans;
}
int sign(long double a) {
  if (a < 0)
    return -1;
  else if (a > 0)
    return 1;
  return 0;
}
struct Vec {
  int x, y;
  friend istream& operator>>(istream& in, Vec& v) {
    in >> v.x >> v.y;
    return in;
  }
};
long double eps = 1e-9;
vector<int> nums;
vector<pair<long long, long long> > primes;
void erat(int n) {
  nums = vector<int>(n + 1);
  for (int i = 2; i <= n; i++)
    if (!nums[i])
      for (int j = 2 * i; j <= n; j += i) nums[j] = 1;
  int c = 0;
  for (int i = 2; i <= n; i++)
    if (!nums[i]) primes.push_back({i, c++});
}
struct node {
  vector<int> sml;
  vector<pair<long long, long long> > prevs;
  vector<long long> prefs;
  node() { sml = vector<int>(168); }
};
struct segtree {
  vector<node> tree;
  int sz;
  segtree(vector<int>& v) {
    sz = 1;
    while (sz < v.size()) sz *= 2;
    v.resize(sz);
    tree.resize(2 * sz - 1);
    vector<int> prev(2e5 + 1, -1);
    for (int i = sz - 1; i < 2 * sz - 1; i++) {
      if (v[i - sz + 1] == 0) break;
      for (auto num : primes) {
        int c = 0;
        while (v[i - sz + 1] % num.first == 0) {
          c++;
          v[i - sz + 1] /= num.first;
        }
        tree[i].sml[num.second] = c;
      }
      if (v[i - sz + 1] > 1) {
        tree[i].prevs.push_back({prev[v[i - sz + 1]], v[i - sz + 1]});
        tree[i].prefs.push_back(v[i - sz + 1]);
        prev[v[i - sz + 1]] = i - sz + 1;
      }
    }
    for (int i = sz - 2; i >= 0; i--) {
      node t1 = tree[2 * i + 1];
      node t2 = tree[2 * i + 2];
      for (int j = 0; j < 168; j++) {
        tree[i].sml[j] = max(t1.sml[j], t2.sml[j]);
      }
      int j1 = 0, j2 = 0;
      sort((t1.prevs).begin(), (t1.prevs).end(),
           [](pair<long long, long long> p1, pair<long long, long long> p2) {
             return p1.second < p2.second;
           });
      sort((t2.prevs).begin(), (t2.prevs).end(),
           [](pair<long long, long long> p1, pair<long long, long long> p2) {
             return p1.second < p2.second;
           });
      while (j1 < t1.prevs.size() && j2 < t2.prevs.size()) {
        if (t1.prevs[j1].second == t2.prevs[j2].second) {
          tree[i].prevs.push_back(t1.prevs[j1]);
          j1++;
          j2++;
        } else if (t1.prevs[j1].second < t2.prevs[j2].second) {
          tree[i].prevs.push_back(t1.prevs[j1]);
          j1++;
        } else {
          tree[i].prevs.push_back(t2.prevs[j2]);
          j2++;
        }
      }
      for (; j1 < t1.prevs.size(); j1++) {
        tree[i].prevs.push_back(t1.prevs[j1]);
      }
      for (; j2 < t2.prevs.size(); j2++) {
        tree[i].prevs.push_back(t2.prevs[j2]);
      }
      sort((tree[i].prevs).begin(), (tree[i].prevs).end());
      if (!tree[i].prevs.empty()) {
        tree[i].prefs.push_back(tree[i].prevs[0].second);
        for (int j = 1; j < tree[i].prevs.size(); j++) {
          tree[i].prefs.push_back(tree[i].prefs[j - 1] *
                                  tree[i].prevs[j].second % INF);
        }
      }
    }
  }
  pair<long long, vector<int> > get(int lx, int rx, int x, int l, int r) {
    if (lx >= r || rx <= l) return {1, vector<int>(168)};
    if (lx >= l && rx <= r) {
      long long ans = 1;
      if (!tree[x].prevs.empty()) {
        auto it = lower_bound((tree[x].prevs).begin(), (tree[x].prevs).end(),
                              make_pair((long long)l, (long long)-INF));
        if (it == tree[x].prevs.end() ||
            (it != tree[x].prevs.begin() && it->first >= l))
          it--;
        if (!tree[x].prevs.empty() && it->first < l)
          ans = tree[x].prefs[it - tree[x].prevs.begin()];
      }
      return {ans, tree[x].sml};
    }
    int m = (lx + rx) / 2;
    auto p1 = get(lx, m, 2 * x + 1, l, r);
    auto p2 = get(m, rx, 2 * x + 2, l, r);
    long long ans = p1.first * p2.first % INF;
    vector<int> sml(168);
    for (int j = 0; j < 168; j++) sml[j] = max(p1.second[j], p2.second[j]);
    return {ans, sml};
  }
  pair<long long, vector<int> > get(int l, int r) {
    return get(0, sz, 0, l, r);
  }
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  erat(1e3);
  segtree seg(a);
  int q;
  cin >> q;
  long long lst = 0;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    int l = (x + lst) % n;
    int r = (y + lst) % n;
    if (l > r) swap(l, r);
    auto p = seg.get(l, r + 1);
    long long res = p.first;
    for (int i = 0; i < 168; i++)
      res = res * binpow(primes[i].first, p.second[i]) % INF;
    lst = res;
    cout << res << '\n';
  }
}
