#include <bits/stdc++.h>
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAXN = (int)1e6 + 5;
using namespace std;
int arr[MAXN];
set<pair<int, int> > st;
map<pair<int, int>, long long> second;
pair<int, int> queries[MAXN];
long long t[MAXN];
long long pre[MAXN];
int l[(int)1e6 + 10];
vector<int> prims;
bool isp[(int)1e6 + 10];
long long n, q;
long long bp(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b / 2;
  }
  return res;
}
void upd(long long i, long long val) {
  for (; i <= n; i += (i & -i)) {
    t[i] = (t[i] * val) % mod;
  }
}
long long que(int i) {
  long long res = 1;
  for (; i > 0; i -= (i & -i)) res = (res * t[i]) % mod;
  return res;
}
void add(long long a, long long ind) {
  for (int i : prims) {
    if (a % i == 0) {
      long long in = bp(i, mod - 2);
      long long val = (1 - in);
      while (val < 0) val += mod;
      upd(l[i] + 1, val);
      upd(ind + 1, bp(val, mod - 2));
      l[i] = ind;
      while (a % i == 0) {
        a /= i;
      }
    }
  }
  if (!isp[a]) {
    long long in = bp(a, mod - 2);
    long long val = (1 - in);
    while (val < 0) val += mod;
    upd(ind + 1, bp(val, mod - 2));
    upd(l[a] + 1, val);
    l[a] = ind;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  pre[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    pre[i] = (pre[i - 1] * arr[i]) % mod;
  }
  t[1] = 1;
  isp[1] = 1;
  for (long long i = 2; i <= 1e6; i++) {
    t[i] = 1;
    if (isp[i]) continue;
    if (i <= (int)1e3) prims.push_back(i);
    for (long long j = i * i; j <= 1e6; j += i) isp[j] = true;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    st.insert(make_pair(r, l));
    queries[i] = make_pair(r, l);
  }
  int r = 1;
  auto it = st.begin();
  while (r <= n) {
    pair<int, int> cur = *it;
    if (it == st.end()) break;
    while (cur.first >= r) {
      add(arr[r], r);
      r++;
    }
    while (it != st.end() && (*it).first == r - 1) {
      pair<int, int> su = *it;
      long long ans = que(su.second);
      long long ans2 = (pre[su.first] * bp(pre[su.second - 1], mod - 2)) % mod;
      second[su] = (ans * ans2) % mod;
      it++;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << second[queries[i]] << '\n';
  }
}
