#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200010, MaxB = 500, MaxA = 1000010, mod = 1000000007;
struct Query {
  int l, r, id;
  bool operator<(const Query &a) const { return r < a.r; }
} q[MaxN];
int n, m, a[MaxN];
vector<pair<int, int> > f[MaxN];
int last[MaxA];
int prime[MaxA], ptot, minp[MaxA];
int inv[MaxA];
bool notp[MaxA];
void init(int n) {
  for (int i = 2; i <= n; ++i) {
    if (!notp[i]) {
      prime[++ptot] = i;
      minp[i] = i;
    }
    for (int j = 1; j <= ptot && prime[j] * i <= n; ++j) {
      notp[prime[j] * i] = 1;
      minp[prime[j] * i] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
  inv[1] = 1;
  for (int i = 2; i <= n; ++i)
    inv[i] = mod - 1ll * (mod / i) * inv[mod % i] % mod;
}
int ans[MaxN];
int c[MaxN];
void modify(int x, int v) {
  for (; x <= n; x += (x & -x)) c[x] = 1ll * c[x] * v % mod;
}
int query(int x) {
  int ret = 1;
  for (; x; x -= (x & -x)) ret = 1ll * ret * c[x] % mod;
  return ret;
}
int main() {
  scanf("%d", &n);
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    mx = max(mx, a[i]);
  }
  init(mx);
  for (int i = 1; i <= n; ++i) {
    int x = a[i];
    while (x != 1) {
      int prod = 1, t = minp[x];
      while (x % t == 0) {
        x /= t;
        prod *= t;
      }
      f[i].push_back(make_pair(t, prod));
    }
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  for (int i = 0; i <= n; ++i) c[i] = 1;
  int node = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto t : f[i]) {
      modify(1, t.second);
      modify(last[t.first] + 1, 1ll * (t.first - 1) * inv[t.first] % mod);
      modify(i + 1, inv[t.second / t.first * (t.first - 1)]);
      last[t.first] = i;
    }
    while (node < m && q[node + 1].r == i) {
      ++node;
      ans[q[node].id] = query(q[node].l);
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
