#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n;
  int mx = 0;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  vector<int> prime, vis(mx + 1), factor(mx + 1), inv(mx + 1), pre(n + 1);
  vector<pair<int, int> > ask[n + 1];
  for (int i = 2; i <= mx; i++) {
    if (!vis[i]) {
      prime.emplace_back(i);
      factor[i] = i;
    }
    for (int j = 0; j < prime.size() && i * prime[j] <= mx; j++) {
      vis[i * prime[j]] = 1;
      factor[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) {
        break;
      }
    }
  }
  vector<int> c(n + 1, 1);
  auto pow_mod = [&](int q, int w) {
    int ret = 1;
    while (w) {
      if (w & 1) ret = 1ll * ret * q % mod;
      q = 1ll * q * q % mod;
      w >>= 1;
    }
    return ret;
  };
  auto lowbit = [&](int x) { return x & (-x); };
  auto upd = [&](int x, int d) {
    while (x <= n) {
      c[x] = 1ll * c[x] * d % mod;
      x += lowbit(x);
    }
  };
  auto query = [&](int x) {
    int ret = 1;
    while (x) {
      ret = 1ll * ret * c[x] % mod;
      x -= lowbit(x);
    }
    return ret;
  };
  inv[0] = 1;
  pre[0] = 1;
  for (int i = 1; i <= n; i++) {
    pre[i] = 1ll * pre[i - 1] * a[i] % mod;
  }
  for (int i = 1; i <= mx; i++) {
    inv[i] = pow_mod(i, mod - 2);
  }
  cin >> q;
  vector<int> pos(mx + 1), res(q + 1);
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    ask[r].emplace_back(l, i);
    res[i] = 1ll * pre[r] * pow_mod(pre[l - 1], mod - 2) % mod;
  }
  for (int i = 1; i <= n; i++) {
    int tmp = a[i];
    while (tmp != 1) {
      int fac = factor[tmp];
      if (pos[fac]) {
        upd(pos[fac], 1ll * fac * inv[fac - 1] % mod);
      }
      pos[fac] = i;
      upd(pos[fac], 1ll * inv[fac] * (fac - 1) % mod);
      while (tmp % fac == 0) tmp /= fac;
    }
    for (auto [l, id] : ask[i]) {
      res[id] =
          1ll * res[id] * query(i) % mod * pow_mod(query(l - 1), mod - 2) % mod;
    }
  }
  for (int i = 1; i <= q; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}
