#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const long long mod = 1e9 + 7;
long long inp1, inp2;
long long n, m, ar[MAXN], ans[MAXN], pro[MAXN];
struct NODE {
  long long l, r, id;
  bool operator<(const NODE& b) const { return r < b.r; }
} q[MAXN];
const int MAXA = 1000005;
long long inv[MAXA], pre[MAXA];
void init_inv() {
  inv[1] = 1;
  for (long long i = 2; i < MAXA; i++)
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
}
const int N = 1000000;
int prime[N + 5], isprime[N + 5], minp[N + 5];
void init_seive(int n) {
  for (int i = 0; i <= n; i++) isprime[i] = 1;
  isprime[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (isprime[i]) prime[++prime[0]] = i;
    for (int j = 1; j <= prime[0] && i * prime[j] <= n; j++) {
      isprime[i * prime[j]] = 0;
      minp[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
}
long long qpow(long long a, long long n) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return ret;
}
long long Inv(long long x) { return qpow(x, mod - 2); }
long long ta[MAXN];
void init_ta() {
  for (long long i = 0; i < MAXN; i++) ta[i] = 1;
}
void mul(long long pos, long long k) {
  for (long long i = pos; i < MAXN; i += i & -i) ta[i] = (ta[i] * k) % mod;
}
long long get(long long pos) {
  long long ret = 1;
  for (long long i = pos; i > 0; i -= i & -i) ret = (ret * ta[i]) % mod;
  return ret;
}
int main() {
  init_seive(N);
  init_inv();
  init_ta();
  scanf("%lld", &n);
  pro[0] = 1;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &ar[i]);
    pro[i] = pro[i - 1] * ar[i] % mod;
  }
  scanf("%lld", &m);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  long long nowp = 0;
  for (long long i = 1; i <= m; i++) {
    while (nowp < q[i].r) {
      ++nowp;
      if (ar[i] == 1) continue;
      while (minp[ar[nowp]]) {
        long long pri = minp[ar[nowp]];
        ar[nowp] /= minp[ar[nowp]];
        if (pre[pri]) {
          mul(pre[pri], pri * inv[pri - 1] % mod);
        }
        mul(nowp, (pri - 1) * inv[pri] % mod);
        pre[pri] = nowp;
      }
      if (ar[nowp] > 1) {
        if (pre[ar[nowp]]) {
          mul(pre[ar[nowp]], ar[nowp] * inv[ar[nowp] - 1] % mod);
        }
        mul(nowp, (ar[nowp] - 1) * inv[ar[nowp]] % mod);
        pre[ar[nowp]] = nowp;
      }
    }
    long long tmp = pro[q[i].r] * Inv(pro[q[i].l - 1]) % mod;
    tmp = tmp * get(q[i].r) % mod * Inv(get(q[i].l - 1)) % mod;
    ans[q[i].id] = tmp;
  }
  for (long long i = 1; i <= m; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
