#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
const int M = 1e6 + 2;
const int mod = 1e9 + 7;
int n, l[N], r[N], lp[M], fen[N], lst[M], ans[N];
vector<int> prm[N];
vector<pair<int, int> > qe[N];
int bp(int a, int n) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = (ret * 1ll * a) % mod;
    a = (a * 1ll * a) % mod;
    n >>= 1;
  }
  return ret;
}
void upd(int pos, int val) {
  for (; pos > 0; pos = (pos & (pos + 1)) - 1)
    fen[pos] = (fen[pos] * 1ll * val) % mod;
}
int get(int r) {
  int ret = 1;
  for (; r < N; r |= r + 1) ret = (ret * 1ll * fen[r]) % mod;
  return ret;
}
int main() {
  for (int i = 2; i < M; i++) {
    if (!lp[i]) {
      lp[i] = i;
      if (i * 1ll * i < M)
        for (int j = i * i; j < M; j += i) lp[j] = i;
    }
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    while (lp[x] > 1) {
      prm[i].push_back(lp[x]);
      x /= lp[x];
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", l + i, r + i);
    qe[r[i]].push_back({l[i], i});
  }
  for (int i = 0; i < N; i++) fen[i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < prm[i].size(); j++) {
      int x = prm[i][j], val;
      val = (bp(x, mod - 2) * 1ll * (x - 1)) % mod;
      if (lst[x]) {
        upd(lst[x], bp(val, mod - 2));
        upd(i, val);
      } else {
        upd(i, val);
      }
      lst[x] = i;
      upd(i, x);
    }
    for (int j = 0; j < qe[i].size(); j++) {
      int id = qe[i][j].second, L = qe[i][j].first;
      ans[id] = get(L);
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
