#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const long long INF = 1e15;
const int N = 3e5 + 2;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
void Fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int n, q;
long long f[1000005], a[200005], g[1000005], cnt[1000005], t[1000005],
    res[200005];
vector<pair<long long, long long> > V[1000005];
long long BinPow(long long n, int k) {
  long long ans = 1, temp = n;
  while (k > 0) {
    if (k & 1) {
      ans = ans * temp % mod;
    }
    temp = temp * temp % mod;
    k >>= 1;
  }
  return ans;
}
long long BIT[200005];
vector<pair<int, int> > Query[200005];
vector<int> Q[1000005];
void Update(long long x, long long val) {
  for (x; x <= n; x += x & -x) {
    BIT[x] = BIT[x] * val % mod;
  }
}
long long Get(long long id) {
  long long ans = 1;
  for (id; id > 0; id -= id & -id) {
    ans = ans * BIT[id] % mod;
  }
  return ans;
}
signed main() {
  Fastio();
  for (int i = 2; i <= 1000; i++) {
    if (f[i] == 0) {
      for (int j = i * i; j <= 1000000; j = j + i) {
        f[j] = i;
      }
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    g[i] = BinPow(i, mod - 2);
    int tmp = i;
    if (f[tmp] == 0) {
      t[tmp] = 1;
      V[i].emplace_back(tmp, tmp);
    } else {
      int nxt = f[tmp];
      while (tmp % nxt == 0) {
        tmp /= nxt;
      }
      V[i].emplace_back(nxt, i / tmp);
      for (auto x : V[tmp]) {
        V[i].emplace_back(x);
      }
      if (V[i].size() == 1) {
        t[i] = t[i / f[i]] + 1;
      }
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    BIT[i] = 1;
    cin >> a[i];
    for (auto x : V[a[i]]) {
      Q[x.first].emplace_back(i);
    }
  }
  g[1] = 1;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    Query[l].emplace_back(r, i);
  }
  for (int i = n; i >= 1; i--) {
    for (auto x : V[a[i]]) {
      Update(i, x.second * (x.first - 1) % mod * g[x.first] % mod);
      auto it = lower_bound(Q[x.first].begin(), Q[x.first].end(), i);
      ++it;
      if (it != Q[x.first].end()) {
        Update(*it, x.first * g[x.first - 1] % mod);
      }
    }
    for (auto x : Query[i]) {
      res[x.second] = Get(x.first);
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << res[i] << '\n';
  }
}
