#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 20, mod = 1e9 + 7;
int n, q, a[N], part[N], ans[N], seg[N << 2];
vector<pair<int, int> > vec[N];
map<int, int> last;
inline int pw(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = ret * 1ll * a % mod;
    a = a * 1ll * a % mod;
    b >>= 1;
  }
  return ret;
}
void build(int v = 1, int s = 0, int e = n) {
  seg[v] = 1;
  if (e - s == 1) return;
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  build(lc, s, mid), build(rc, mid, e);
}
void modify(int idx, int val, int v = 1, int s = 0, int e = n) {
  if (s + 1 == e) {
    seg[v] = seg[v] * 1ll * val % mod;
    return;
  }
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  if (idx < mid)
    modify(idx, val, lc, s, mid);
  else
    modify(idx, val, rc, mid, e);
  seg[v] = seg[lc] * 1ll * seg[rc] % mod;
}
int get(int l, int r, int v = 1, int s = 0, int e = n) {
  if (s >= r || e <= l) return 1;
  if (s >= l && e <= r) return seg[v];
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  return get(l, r, lc, s, mid) * 1ll * get(l, r, rc, mid, e) % mod;
}
int32_t main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i), part[i] = (i ? part[i - 1] : 1) * 1ll * a[i] % mod;
  scanf("%d", &q);
  for (int i = 0, l, r; i < q; i++)
    scanf("%d %d", &l, &r), vec[--r].push_back({--l, i}),
        ans[i] = part[r] * 1ll * (l ? pw(part[l - 1], mod - 2) : 1) % mod;
  build();
  for (int r = 0; r < n; r++) {
    for (int i = 2; i * i <= a[r]; i++) {
      if (a[r] % i == 0) {
        if (last.count(i)) modify(last[i], i * 1ll * pw(i - 1, mod - 2) % mod);
        modify(r, (i - 1) * 1ll * pw(i, mod - 2) % mod);
        last[i] = r;
      }
      while (a[r] % i == 0) a[r] /= i;
    }
    {
      int i = a[r];
      if (i != 1) {
        if (last.count(i)) modify(last[i], i * 1ll * pw(i - 1, mod - 2) % mod);
        modify(r, (i - 1) * 1ll * pw(i, mod - 2) % mod);
        last[i] = r;
      }
    }
    for (pair<int, int> p : vec[r]) {
      int l, i;
      tie(l, i) = p;
      ans[i] = ans[i] * 1ll * get(l, r + 1) % mod;
    }
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
}
