#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, block = 450, mod = 1e9 + 7;
int pw(int a, int n) {
  int y = 1;
  for (; n; n /= 2) {
    if (n & 1) y = 1ll * y * a % mod;
    a = 1ll * a * a % mod;
  }
  return y;
}
int inv(int a) { return pw(a, mod - 2); }
int x, n, a, lp[1000006], A[N], B[N], PR[N], IN[1000006], GIN[1000006], QL[N],
    QR[N], G[N], L, R, iPR[N], num[1000006], adit = 1, md = 1, ans[N];
bool cmp(int i, int j) {
  return (QL[i] / block == QL[j] / block ? QR[i] < QR[j] : QL[i] < QL[j]);
}
vector<pair<int, int> > primes[N];
bool isp[1000006];
void sieve() {
  memset(isp, 1, sizeof isp);
  isp[1] = 0;
  lp[1] = 1;
  long long j;
  for (int i = 2; i <= 1000000; i++) {
    if (isp[i]) {
      lp[i] = i;
      IN[i] = inv(i);
      GIN[i] = inv(i - 1);
      for (j = 1ll * i * i; j <= 1000000; j += i) {
        isp[j] = 0;
        if (!lp[j]) lp[j] = i;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  sieve();
  cin >> n;
  iPR[0] = PR[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    PR[i] = 1ll * PR[i - 1] * x % mod;
    iPR[i] = inv(PR[i]);
    while (x > 1) {
      a = lp[x];
      int t = 0;
      while (x % a == 0) x /= a, t++;
      primes[i].push_back({a, t});
    }
  }
  int cl = 0, cr = 0, q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> QL[i] >> QR[i];
    G[i] = i;
  }
  sort(G + 1, G + q + 1, cmp);
  for (int i = 1; i <= q; i++) {
    L = QL[G[i]];
    R = QR[G[i]];
    while (cl > L) {
      cl--;
      for (auto j : primes[cl]) {
        if (!num[j.first]) {
          adit = 1ll * adit * IN[j.first] % mod;
          md = 1ll * md * (j.first - 1) % mod;
        }
        num[j.first] += j.second;
      }
    }
    while (cr < R) {
      cr++;
      for (auto j : primes[cr]) {
        if (!num[j.first]) {
          adit = 1ll * adit * IN[j.first] % mod;
          md = 1ll * md * (j.first - 1) % mod;
        }
        num[j.first] += j.second;
      }
    }
    while (cl < L) {
      for (auto j : primes[cl]) {
        num[j.first] -= j.second;
        if (!num[j.first]) {
          adit = 1ll * adit * j.first % mod;
          md = 1ll * md * GIN[j.first] % mod;
        }
      }
      cl++;
    }
    while (cr > R) {
      for (auto j : primes[cr]) {
        num[j.first] -= j.second;
        if (!num[j.first]) {
          adit = 1ll * adit * j.first % mod;
          md = 1ll * md * GIN[j.first] % mod;
        }
      }
      cr--;
    }
    ans[G[i]] = 1ll * PR[QR[G[i]]] * iPR[QL[G[i]] - 1] % mod;
    ans[G[i]] = 1ll * ans[G[i]] * (1ll * adit * md % mod) % mod;
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}
