#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7, MN = 2e5 + 10, MV = 1e6 + 10;
int n, q;
int arr[MN];
vector<pair<int, int> > qr[MN];
bool pr[MV];
int dv[MV];
int P[MV], Q[MV];
int lst[MV];
int pmul[MN];
int ans[MN], seg[MN << 2];
int bpw(int a, int b) {
  if (!b) return 1;
  int t = bpw(a, b / 2);
  t = 1ll * t * t % MOD;
  if (b & 1)
    return 1ll * t * a % MOD;
  else
    return t;
}
void input() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    qr[r].push_back(make_pair(l, i));
  }
}
void prep() {
  for (int i = 2; i < MV; ++i) {
    if (pr[i]) continue;
    P[i] = (1ll * (i - 1) * bpw(i, MOD - 2)) % MOD;
    Q[i] = (1ll * i * bpw((i - 1), MOD - 2)) % MOD;
    for (int j = 2 * i; j < MV; j += i) {
      pr[j] = true;
      if (dv[j]) continue;
      dv[j] = i;
    }
  }
}
void upd(int id, int left, int right, int p, int val) {
  seg[id] = (1ll * seg[id] * val) % MOD;
  if (left == right) return;
  int mid = (left + right) >> 1;
  if (p <= mid)
    upd(2 * id, left, mid, p, val);
  else
    upd(2 * id + 1, mid + 1, right, p, val);
}
int get(int id, int left, int right, int l, int r) {
  if (r < left || right < l) return 1;
  if (l <= left && right <= r) return seg[id];
  int mid = (left + right) >> 1;
  return (1ll * get(2 * id, left, mid, l, r) *
          get(2 * id + 1, mid + 1, right, l, r)) %
         MOD;
}
void change(int t, int ind) {
  if (~lst[t]) upd(1, 0, n - 1, lst[t], Q[t]);
  lst[t] = ind;
  upd(1, 0, n - 1, lst[t], P[t]);
}
void solve() {
  memset(lst, -1, sizeof lst);
  fill(seg, seg + (MN << 2), 1);
  pmul[0] = 1;
  for (int i = 0; i < n; ++i) pmul[i + 1] = (1ll * arr[i] * pmul[i]) % MOD;
  for (int i = 0; i < n; ++i) {
    int t = arr[i];
    while (dv[t]) {
      change(dv[t], i);
      int tmp = dv[t];
      while (t % tmp == 0) t /= tmp;
    }
    if (t != 1) {
      change(t, i);
      int tmp = t;
      while (t % tmp == 0) t /= tmp;
    }
    for (int j = 0; j < ((int)(qr[i]).size()); ++j)
      ans[qr[i][j].second] = 1ll * pmul[i + 1] *
                             bpw(pmul[qr[i][j].first], MOD - 2) % MOD *
                             get(1, 0, n - 1, qr[i][j].first, i) % MOD;
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << endl;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  prep();
  solve();
  return 0;
}
