#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int mod = 1e9 + 7;
int n, m, lim, blo, a[maxn], b[maxn], cnt[maxn * 5], sum[maxn][200], ans1[maxn],
    ans2[maxn], now1 = 1, now2 = 1, pri[1010], tot;
bool vis[1010];
struct Query {
  int l, r, id;
} q[maxn];
inline bool cmp(const Query &a, const Query &b) {
  if ((a.l - 1) / blo != (b.l - 1) / blo)
    return (a.l - 1) / blo < (b.l - 1) / blo;
  return a.r < b.r;
}
inline int read() {
  register int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return (f == 1) ? x : -x;
}
inline int fpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ret = 1ll * ret * a % mod;
  return ret;
}
inline void sieve(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++tot] = i;
    for (int j = 1; j <= tot && i * pri[j] <= n; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
inline void solve(int x, int n) {
  int val;
  for (int i = 1; i <= tot && pri[i] <= n; i++)
    if (n % pri[i] == 0) {
      val = 1;
      while (n % pri[i] == 0) n /= pri[i], val *= pri[i];
      sum[x][i] = val;
    }
  if (n > 1) b[x] = n;
}
inline void add(int x) {
  if (!b[x]) return;
  if (++cnt[b[x]] == 1)
    now1 = 1ll * now1 * (b[x] - 1) % mod;
  else
    now1 = 1ll * now1 * b[x] % mod;
}
inline void del(int x) {
  if (!b[x]) return;
  if (--cnt[b[x]] == 0)
    now2 = 1ll * now2 * (b[x] - 1) % mod;
  else
    now2 = 1ll * now2 * b[x] % mod;
}
int main() {
  n = read();
  blo = 1220;
  for (int i = 1; i <= n; i++) a[i] = read(), lim = max(lim, a[i]);
  sieve((int)sqrt(lim));
  for (int i = 1; i <= n; i++) solve(i, a[i]);
  for (int j = 1; j <= tot; j++) {
    sum[0][j] = 1;
    for (int i = 1; i <= n; i++) {
      if (!sum[i][j])
        sum[i][j] = sum[i - 1][j];
      else
        sum[i][j] = 1ll * sum[i][j] * sum[i - 1][j] % mod;
    }
  }
  m = read();
  for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read(), q[i].id = i;
  sort(q + 1, q + m + 1, cmp);
  int L = 1, R = 0;
  for (int i = 1; i <= m; i++) {
    while (R < q[i].r) add(++R);
    while (R > q[i].r) del(R--);
    while (L < q[i].l) del(L++);
    while (L > q[i].l) add(--L);
    ans1[q[i].id] = now1;
    ans2[q[i].id] = now2;
    for (int j = 1; j <= tot; j++) {
      if (sum[q[i].r][j] == sum[q[i].l - 1][j]) continue;
      ans1[q[i].id] =
          1ll * ans1[q[i].id] * sum[q[i].r][j] % mod * (pri[j] - 1) % mod;
      ans2[q[i].id] =
          1ll * ans2[q[i].id] * sum[q[i].l - 1][j] % mod * pri[j] % mod;
    }
  }
  for (int i = 1; i <= m; i++)
    printf("%d\n", 1ll * ans1[i] * fpow(ans2[i], mod - 2) % mod);
  return 0;
}
