#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b;
long long A[MAXN];
long long ps[MAXN];
long long fen[MAXN];
long long ans[MAXN];
long long F[MAXN];
long long I[MAXN];
int sieve[MAXN];
int last[MAXN];
vector<pair<int, int> > query[MAXN];
long long powmod(long long a, long long b) {
  if (!b) return 1;
  if (b & 1) return a * powmod(a * a % mod, b >> 1) % mod;
  return powmod(a * a % mod, b >> 1);
}
long long inv(long long x) {
  if (x < MAXN) return I[x];
  return powmod(x, mod - 2);
}
void update(int pos, long long val) {
  if (!pos) return;
  for (; pos < MAXN; pos += pos & -pos) fen[pos] = fen[pos] * val % mod;
}
long long get(int pos) {
  long long res = 1;
  for (; pos; pos -= pos & -pos) res = res * fen[pos] % mod;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i < MAXN; i++)
    if (!sieve[i])
      for (int j = i; j < MAXN; j += i) sieve[j] = i;
  F[0] = 1;
  for (int i = 1; i < MAXN; i++) F[i] = F[i - 1] * i % mod;
  I[MAXN - 1] = powmod(F[MAXN - 1], mod - 2);
  for (int i = MAXN - 1; i; i--) I[i - 1] = I[i] * i % mod;
  for (int i = 1; i < MAXN; i++) I[i] = I[i] * F[i - 1] % mod;
  I[0] = 0;
  cin >> n;
  ps[0] = 1;
  for (int i = 1; i <= n; i++) cin >> A[i], ps[i] = ps[i - 1] * A[i] % mod;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    ans[i] = ps[y] * inv(ps[x - 1]) % mod;
    query[y].push_back({x, i});
  }
  fill(fen, fen + MAXN, 1);
  for (int i = 1; i <= n; i++) {
    for (int tmp = A[i]; tmp > 1;) {
      int p = sieve[tmp];
      while (tmp % p == 0) tmp /= p;
      update(last[p], p * inv(p - 1) % mod);
      last[p] = i;
      update(i, (p - 1) * inv(p) % mod);
    }
    long long tmp = get(i);
    for (pair<int, int> p : query[i])
      ans[p.second] *= tmp * inv(get(p.first - 1)) % mod;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] % mod << '\n';
  return 0;
}
