#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1e6 + 10, MOD = 1e9 + 7;
int n, Q, m, a[N], last[M], v[M], prm[M], inv[M], ans[N];
struct Query {
  int l, r, id;
} ask[N];
bool cmp(Query x, Query y) { return x.r < y.r; }
void findprm(int k) {
  for (int i = 2; i <= k; i++) {
    if (!v[i]) {
      v[i] = i;
      prm[++m] = i;
    }
    for (int j = 1; j <= m; j++) {
      if (1LL * prm[j] * i > k || v[i] < prm[j]) break;
      v[prm[j] * i] = prm[j];
    }
  }
}
long long fpow(long long x, long long k, long long p) {
  long long ans = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) ans = ans * x % p;
  return ans;
}
struct Seg {
  int l[N * 4], r[N * 4];
  long long mul[N * 4];
  void pushup(int x) { mul[x] = mul[x * 2] * mul[x * 2 + 1] % MOD; }
  void build(int x, int ql, int qr) {
    l[x] = ql;
    r[x] = qr;
    if (ql == qr) {
      mul[x] = a[ql];
      return;
    }
    int mid = (ql + qr) >> 1;
    build(x * 2, ql, mid);
    build(x * 2 + 1, mid + 1, qr);
    pushup(x);
  }
  void update(int x, int k, int val) {
    if (l[x] == k && r[x] == k) {
      mul[x] = mul[x] * val % MOD;
      return;
    }
    int mid = (l[x] + r[x]) >> 1;
    if (k <= mid)
      update(x * 2, k, val);
    else
      update(x * 2 + 1, k, val);
    pushup(x);
  }
  long long query(int x, int ql, int qr) {
    if (l[x] == ql && r[x] == qr) return mul[x];
    int mid = (l[x] + r[x]) >> 1;
    if (qr <= mid)
      return query(x * 2, ql, qr);
    else if (ql > mid)
      return query(x * 2 + 1, ql, qr);
    else
      return query(x * 2, ql, mid) * query(x * 2 + 1, mid + 1, qr) % MOD;
  }
} seg;
int main() {
  findprm(M - 10);
  inv[0] = 1;
  for (int i = 1; i <= M - 10; i++) inv[i] = fpow(i, MOD - 2, MOD);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  seg.build(1, 1, n);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &ask[i].l, &ask[i].r);
    ask[i].id = i;
  }
  sort(ask + 1, ask + 1 + Q, cmp);
  for (int i = 1, j = 1; i <= Q; i++) {
    for (; j <= ask[i].r; j++)
      for (int k = a[j]; k > 1;) {
        int d = v[k];
        if (last[d]) seg.update(1, last[d], d);
        if (last[d]) seg.update(1, last[d], inv[d - 1]);
        last[d] = j;
        seg.update(1, j, inv[d]);
        seg.update(1, j, d - 1);
        while (k % d == 0) k /= d;
      }
    ans[ask[i].id] = seg.query(1, ask[i].l, ask[i].r);
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
