#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long double Pi = acos(-1.0), E = exp(1.0);
const long double Lucky_Number =
    E * (pow((E + Pi) * (E + E + Pi), E)) +
    (E / ((pow(Pi, E) - E) * (E + pow(E, Pi) - pow(Pi, E))));
char Buf[1 << 22], *P1 = Buf, *P2 = Buf;
inline int read() {
  int x = 0;
  char ch =
      (P1 == P2 && (P2 = (P1 = Buf) + fread(Buf, 1, (1 << 22) - 10, stdin),
                    P1 == P2)
           ? EOF
           : *P1++);
  while (!isdigit(ch))
    ch = (P1 == P2 && (P2 = (P1 = Buf) + fread(Buf, 1, (1 << 22) - 10, stdin),
                       P1 == P2)
              ? EOF
              : *P1++);
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = (P1 == P2 && (P2 = (P1 = Buf) + fread(Buf, 1, (1 << 22) - 10, stdin),
                       P1 == P2)
              ? EOF
              : *P1++);
  }
  return x;
}
const int Max = 2e5 + 100;
const long long mod = 1000000007;
inline long long qpow(long long x, long long y) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = ans * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
inline long long inv(long long x) { return qpow(x, mod - 2); }
namespace sgt {
long long sum[Max << 2];
void build(int p, int l, int r) {
  sum[p] = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(((p) << 1), l, mid);
  build(((p) << 1 | 1), mid + 1, r);
}
void modify(const int &x, int p, int l, int r, const long long &k) {
  sum[p] = sum[p] * k % mod;
  if (l == x && r == x) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    modify(x, ((p) << 1), l, mid, k);
  else
    modify(x, ((p) << 1 | 1), mid + 1, r, k);
}
long long query(const int &ql, const int &qr, int p, int l, int r) {
  if (l >= ql && r <= qr) return sum[p];
  int mid = (l + r) >> 1;
  long long ans = 1;
  if (ql <= mid) ans = ans * query(ql, qr, ((p) << 1), l, mid) % mod;
  if (qr >= mid + 1)
    ans = ans * query(ql, qr, ((p) << 1 | 1), mid + 1, r) % mod;
  return ans;
}
}  // namespace sgt
using sgt::modify;
using sgt::query;
int a[Max], pos[Max * 5], n, m;
bool isprime[Max * 5];
int prime[Max * 5], pn;
long long sum[Max];
void init_prime(const int &n) {
  memset(isprime, true, sizeof(isprime));
  isprime[0] = isprime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (isprime[i]) prime[++pn] = i;
    for (int j = 1; j <= pn && i * prime[j] <= n; ++j) {
      isprime[i * prime[j]] = false;
      if (i % prime[j] == 0) break;
    }
  }
}
void solve(int id) {
  int x = a[id], y = x;
  for (int i = 1; 1ll * prime[i] * prime[i] <= x && i <= pn; ++i) {
    if (y % prime[i] == 0) {
      if (pos[prime[i]])
        modify(pos[prime[i]], 1, 1, n,
               1ll * prime[i] * inv(prime[i] - 1) % mod);
      pos[prime[i]] = id;
      modify(id, 1, 1, n, 1ll * (prime[i] - 1) * inv(prime[i]) % mod);
      while (y % prime[i] == 0) y /= prime[i];
    }
  }
  if (y != 1) {
    if (pos[y]) modify(pos[y], 1, 1, n, 1ll * y * inv(y - 1) % mod);
    pos[y] = id;
    modify(id, 1, 1, n, 1ll * (y - 1) * inv(y) % mod);
  }
}
struct node {
  int l, r, id;
  inline bool operator<(const node &a) const { return r < a.r; }
} q[Max];
long long res[Max];
int main() {
  init_prime(1e6);
  n = read();
  sgt::build(1, 1, n);
  sum[0] = 1;
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    sum[i] = sum[i - 1] * a[i] % 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);
  for (int i = 1, j = 1; i <= m; ++i) {
    for (; j <= n && j <= q[i].r; ++j) solve(j);
    int l = q[i].l, r = q[i].r;
    long long t = sum[r] * inv(sum[l - 1]) % mod;
    res[q[i].id] = t * query(l, r, 1, 1, n) % mod;
  }
  for (int i = 1; i <= m; ++i) printf("%lld\n", res[i]);
  return 0;
}
