#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 1e6 + 10;
long long fen[N];
void update(long long x, long long val) {
  for (long long i = x; i < N; i += i & -i) fen[i] = fen[i] * val % M;
}
long long query(long long x) {
  long long res = 1;
  for (long long i = x; i; i -= i & -i) res = res * fen[i] % M;
  return res;
}
long long LP[N];
long long invp[N];
long long invpp[N];
long long iv[N];
long long powM(long long a, long long b) {
  long long res = 1;
  for (; b; b /= 2, a = a * a % M)
    if (b % 2) res = res * a % M;
  return res;
}
long long inv(long long x) { return powM(x, M - 2); }
void seive() {
  LP[1] = 1;
  iv[1] = 1;
  invp[1] = 1;
  invpp[1] = 1;
  for (long long i = 2; i < N; i++) {
    iv[i] = inv(i);
    if (!LP[i]) {
      invp[i] = inv(i);
      invpp[i] = inv(i - 1);
      for (long long j = i; j < N; j += i) {
        LP[j] = i;
      }
    }
  }
}
map<long long, vector<long long>> mp;
vector<long long> pr[N];
void add(long long val, long long ind) {
  long long z = val;
  if (pr[val].size() == 0) {
    while (val != 1) {
      long long p = LP[val];
      while (val % p == 0) val /= p;
      pr[z].push_back(p);
    }
  }
  for (long long x : pr[z]) {
    mp[x].push_back(ind);
  }
}
void sub(long long ind, long long val) {
  update(ind, iv[val]);
  for (long long x : pr[val]) {
    assert(mp[x].back() == ind);
    mp[x].pop_back();
    long long uval = x * invpp[x] % M;
    update(ind, uval);
    if (mp[x].size() == 0)
      mp.erase(x);
    else {
      long long nt = mp[x].back();
      long long u = (x - 1) * invp[x] % M;
      update(nt, u);
    }
  }
}
signed main() {
  seive();
  fill(fen, fen + N, 1);
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    update(i, a[i]);
    add(a[i], i);
  }
  for (auto &x : mp) {
    sort(x.second.begin(), x.second.end(), greater<long long>());
    long long ind = x.second.back();
    long long val = x.first;
    long long uval = (val - 1) * invp[val] % M;
    update(ind, uval);
  }
  vector<array<long long, 3>> p;
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    p.push_back({l, r, i});
  }
  long long ans[q];
  sort(p.begin(), p.end());
  long long cl = 1;
  for (long long i = 0; i < q; i++) {
    long long id = p[i][2];
    long long l = p[i][0];
    long long r = p[i][1];
    while (cl < l) {
      sub(cl, a[cl]);
      cl++;
    }
    ans[id] = query(r);
  }
  for (long long i = 0; i < q; i++) cout << ans[i] << endl;
}
