#include <bits/stdc++.h>
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int tot, n, m, pri[M], inv[M], minx[M], last[M];
long long s[N], s2[N], f[N], a[N];
bool flag[M];
struct node {
  int l, r, id;
  long long ans;
} q[N];
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long tmp = power(a, b >> 1);
  tmp = tmp * tmp % mod;
  if (b & 1) tmp = tmp * a % mod;
  return tmp;
}
void pre() {
  for (int i = 2; i <= 1e6; i++) {
    if (!flag[i]) pri[++tot] = i, minx[i] = i;
    for (int j = 1; j <= tot; j++) {
      if ((long long)i * pri[j] > 1e6) break;
      flag[i * pri[j]] = 1;
      minx[i * pri[j]] = pri[j];
      if (i % pri[j] == 0) break;
    }
  }
  for (int i = 1; i <= 1e6; i++) inv[i] = power(i, mod - 2);
}
bool cmp(node a, node b) { return a.r < b.r; }
bool cmp2(node a, node b) { return a.id < b.id; }
int lowbit(int x) { return x & (-x); }
void add(int x, long long y) {
  while (x <= n) {
    f[x] = f[x] * y % mod;
    x += lowbit(x);
  }
}
long long sum(int x) {
  long long tmp = 1;
  while (x) {
    tmp = tmp * f[x] % mod;
    x -= lowbit(x);
  }
  return tmp;
}
int main() {
  pre();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  s[0] = 1;
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] * a[i] % mod;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r);
  for (int i = 1; i <= m; i++) q[i].id = i;
  std::sort(q + 1, q + 1 + m, cmp);
  for (int i = 1; i <= n; i++) s2[i] = f[i] = 1;
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    while (x > 1) {
      int tmp = minx[x];
      while (x % tmp == 0) x /= tmp;
      s2[i] = s2[i] * (tmp - 1) % mod * inv[tmp] % mod;
    }
  }
  s2[0] = 1;
  for (int i = 1; i <= n; i++) s2[i] = s2[i - 1] * s2[i] % mod;
  int now = 0;
  for (int i = 1; i <= m; i++) {
    while (now < q[i].r) {
      now++;
      while (a[now] > 1) {
        int tmp = minx[a[now]];
        while (a[now] % tmp == 0) a[now] /= tmp;
        add(last[tmp] + 1, (long long)(tmp - 1) * inv[tmp] % mod);
        last[tmp] = now;
      }
    }
    long long ans = s[q[i].r] * power(s[q[i].l - 1], mod - 2) % mod;
    ans = ans * power(s2[q[i].l - 1], mod - 2) % mod;
    ans = ans * sum(q[i].l) % mod;
    q[i].ans = ans;
  }
  std::sort(q + 1, q + 1 + m, cmp2);
  for (int i = 1; i <= m; i++) printf("%I64d\n", q[i].ans);
  return 0;
}
