#include <bits/stdc++.h>
using namespace std;
int mul(int a, int b) {
  long long c = 1LL * a * b;
  return c >= ((long long)1e9 + 7) ? c % ((long long)1e9 + 7) : c;
}
int modpow(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
struct STNode {
  int val;
  STNode *left_child, *right_child;
  STNode() {}
  STNode(int l, int r) {
    val = 1;
    if (l != r) {
      int mid = (l + r) >> 1;
      left_child = new STNode(l, mid);
      right_child = new STNode(mid + 1, r);
    }
  }
  STNode *copy() {
    STNode *node = new STNode();
    node->val = val;
    node->left_child = left_child, node->right_child = right_child;
    return node;
  }
  STNode *update(int l, int r, int p, int v) {
    STNode *node = copy();
    if (l == r) {
      node->val = mul(val, v);
    } else {
      int mid = (l + r) >> 1;
      if (p <= mid) {
        node->left_child = node->left_child->update(l, mid, p, v);
      } else {
        node->right_child = node->right_child->update(mid + 1, r, p, v);
      }
      node->val = mul(node->left_child->val, node->right_child->val);
    }
    return node;
  }
  int query(int _l, int _r, int l, int r) {
    if (_l > r || _r < l) {
      return 1;
    } else if (_l >= l && _r <= r) {
      return val;
    } else {
      int mid = (_l + _r) >> 1;
      return mul(left_child->query(_l, mid, l, r),
                 right_child->query(mid + 1, _r, l, r));
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  vector<vector<pair<int, int>>> factors(200005);
  for (int i = 2; i < 200005; ++i) {
    if (factors[i].empty()) {
      for (int j = i; j < 200005; j += i) {
        factors[j].push_back({i, 0});
        int m = j;
        while (m % i == 0) {
          factors[j].back().second++;
          m /= i;
        }
      }
    }
  }
  int n;
  cin >> n;
  vector<STNode *> roots;
  map<int, deque<pair<int, int>>> primes;
  roots.push_back(new STNode(1, n));
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    roots.push_back(roots.back()->update(1, n, 1, 1));
    for (auto &it : factors[x]) {
      if (primes.count(it.first)) {
        int f = it.second;
        deque<pair<int, int>> &arr = primes[it.first];
        while (!arr.empty() && f > 0) {
          int &old_f = arr.back().first;
          int old_p = arr.back().second;
          int exp = min(old_f, f);
          int inv = modpow(modpow(it.first, exp), ((long long)1e9 + 7) - 2);
          roots.back() = roots.back()->update(1, n, old_p, inv);
          f -= exp;
          old_f -= exp;
          if (old_f == 0) arr.pop_back();
        }
      }
      roots.back() = roots.back()->update(1, n, i, modpow(it.first, it.second));
      primes[it.first].push_back({it.second, i});
    }
  }
  int q, last = 0;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n + 1;
    int r = (last + y) % n + 1;
    if (l > r) swap(l, r);
    int rv = roots[r]->query(1, n, 1, r);
    int lv = modpow(roots[r]->query(1, n, 1, l - 1), ((long long)1e9 + 7) - 2);
    cout << (last = mul(rv, lv)) << "\n";
  }
}
