#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 2e5 + 5;
constexpr LL MOD = 1e9 + 7;
constexpr int maxv = 1e6 + 100;
int n, q;
int a[N], last[maxv];
vector<pair<int, int>> dat[N];
int ans[N];
bitset<maxv> status;
vector<int> primes;
LL fen[N];
LL power(LL a, int b) {
  LL rev = 1;
  while (b) {
    if (b & 1) rev = rev * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return rev;
}
void update(int k, int val) {
  while (k < N) {
    (fen[k] *= val) %= MOD;
    k += k & -k;
  }
}
LL query(int k) {
  LL rev = 1;
  while (k > 0) {
    (rev *= fen[k]) %= MOD;
    k -= k & -k;
  }
  return rev;
}
void gen() {
  for (int p = 2; p * p < maxv; p++) {
    if (!status[p]) {
      primes.push_back(p);
      for (int j = p * 2; j < maxv; j += p) status[j] = 1;
    }
  }
}
void load() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    dat[r].push_back({l, i});
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  fill(begin(fen), end(fen), 1);
  gen();
  load();
  for (int i = 1; i <= n; i++) {
    update(i, a[i]);
    for (const auto& p : primes) {
      if (a[i] % p == 0) {
        if (last[p]) update(last[p], p * power(p - 1, MOD - 2) % MOD);
        update(i, (p - 1) * power(p, MOD - 2) % MOD);
        last[p] = i;
        while (a[i] % p == 0) a[i] /= p;
      }
    }
    if (a[i] > 1) {
      if (last[a[i]]) update(last[a[i]], a[i] * power(a[i] - 1, MOD - 2) % MOD);
      last[a[i]] = i;
      update(i, (a[i] - 1) * power(a[i], MOD - 2) % MOD);
    }
    for (auto x : dat[i]) {
      ans[x.second] = query(i) * power(query(x.first - 1), MOD - 2) % MOD;
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
}
