#include <bits/stdc++.h>
using namespace std;
const int N = 200005, P = 1000000007, MX = 1000000, M = MX + 5;
using ll = long long;
int n, pr[N], ptr, g[M], lst[M];
ll a[N], pre[N], ans[N];
ll qpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ret;
}
struct TNode {
  int l, r;
  ll v;
} t[N << 2];
inline int lc(int pos) { return pos << 1; }
inline int rc(int pos) { return pos << 1 | 1; }
void build(int pos, int l, int r) {
  t[pos].l = l;
  t[pos].r = r;
  t[pos].v = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(lc(pos), l, mid);
  build(rc(pos), mid + 1, r);
}
void modify(int pos, int p, int v) {
  if (t[pos].l == t[pos].r) {
    t[pos].v = t[pos].v * v % P;
    return;
  }
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (p <= mid)
    modify(lc(pos), p, v);
  else
    modify(rc(pos), p, v);
  t[pos].v = t[lc(pos)].v * t[rc(pos)].v % P;
}
ll query(int pos, int l, int r) {
  if (t[pos].l == l && t[pos].r == r) return t[pos].v;
  int mid = (t[pos].l + t[pos].r) >> 1;
  if (r <= mid)
    return query(lc(pos), l, r);
  else if (l > mid)
    return query(rc(pos), l, r);
  else
    return query(lc(pos), l, mid) * query(rc(pos), mid + 1, r) % P;
}
struct Query {
  int l, r, id;
} q[N];
int main() {
  ios::sync_with_stdio(false);
  for (int i = 2; i <= MX; i++) {
    if (!g[i]) g[i] = i, pr[++ptr] = i;
    for (int j = 1; j <= ptr && i * pr[j] <= MX; j++) {
      g[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  pre[0] = 1;
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] * a[i] % P;
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> q[i].l >> q[i].r, q[i].id = i;
  sort(q + 1, q + m + 1, [](Query a, Query b) { return a.r < b.r; });
  build(1, 1, n);
  for (int i = 1, j = 1; i <= n; i++) {
    while (a[i] > 1) {
      int t = g[a[i]];
      if (lst[t]) modify(1, lst[t], t * qpow(t - 1, P - 2) % P);
      modify(1, i, (t - 1) * qpow(t, P - 2) % P);
      lst[t] = i;
      while (a[i] % t == 0) a[i] /= t;
    }
    while (j <= m && q[j].r == i)
      ans[q[j].id] = pre[q[j].r] * qpow(pre[q[j].l - 1], P - 2) % P *
                     query(1, q[j].l, q[j].r) % P,
      ++j;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << endl;
  return 0;
}
