#include <bits/stdc++.h>
using namespace std;
int n, a[200007], q;
int l[200007], r[200007], prime[1000007], id[1000007];
long long bit[200007], ans[200007], inv[1000007], prd[200007], divide[200007],
    cal[1000007];
vector<pair<int, int> > query[200007];
vector<int> dv[200007];
const long long mod = 1e9 + 7;
long long pw(long long a, long long b) {
  if (b == 1) return a;
  long long ret = pw(a, b / 2);
  if (b % 2 == 0) return ret * ret % mod;
  return ret * ret % mod * a % mod;
}
void upd(int pos, long long val) {
  for (int i = pos; i <= n; i += i & -i) bit[i] = bit[i] * val % mod;
}
long long get(int pos) {
  long long res = 1;
  for (int i = pos; i >= 1; i -= i & -i) {
    res = (res * bit[i]) % mod;
  }
  return res;
}
long long get(int l, int r) { return (get(r) * pw(get(l - 1), mod - 2)) % mod; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i]) continue;
    for (int j = i; j <= 1000000; j += i) {
      if (!prime[j]) prime[j] = i;
    }
  }
  inv[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    inv[i] = pw(i, mod - 2);
    if (prime[i] == i) cal[i] = 1LL * (i - 1) * inv[i] % mod;
  }
  prd[0] = 1, divide[0] = 1;
  for (int i = 1; i <= n; i++)
    prd[i] = (prd[i - 1] * 1LL * a[i]) % mod,
    divide[i] = (divide[i - 1] * inv[a[i]]) % mod;
  for (int i = 1; i <= n; i++) {
    bit[i] = 1;
    int cur = a[i], prv = 1;
    while (cur > 1) {
      if (prime[cur] != prv) {
        prv = prime[cur];
        dv[i].push_back(prv);
      }
      cur /= prv;
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &l[i], &r[i]);
    ans[i] = (prd[r[i]] * divide[l[i] - 1]) % mod;
    query[r[i]].push_back(make_pair(l[i], i));
  }
  for (int i = 1; i <= n; i++) {
    for (int j : dv[i]) {
      int pos = id[j];
      if (pos) upd(pos, 1LL * j * inv[j - 1] % mod);
      upd(i, cal[j]);
      id[j] = i;
    }
    for (int j = 0; j < (int)query[i].size(); j++) {
      int L = query[i][j].first;
      int idx = query[i][j].second;
      ans[idx] = (ans[idx] * get(L, i)) % mod;
    }
  }
  for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
}
