#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7, base = 311;
const int M = 1e6 + 5;
template <class X, class Y>
bool maximize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x + eps < y) {
    x = y;
    return true;
  } else
    return false;
}
struct hi {
  int l, r;
} BIT[N];
int n, m, a[N];
int max1 = 0, f[N], ans[N];
int kt[N], id[M], div1[M], up[M];
void nhap() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = 1;
    maximize(max1, a[i]);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    BIT[i].l = kt[u];
    kt[u] = i;
    BIT[i].r = v;
  }
}
void init() {
  up[1] = 1;
  for (int i = 2; i <= max1; i++) {
    if (!div1[i])
      for (int j = i; j <= max1; j += i) div1[j] = i;
    up[i] = 1LL * up[mod % i] * (mod - mod / i) % mod;
  }
}
void ud(int x, int val) {
  for (; x <= n; x += (x & -x)) f[x] = 1LL * f[x] * val % mod;
}
int query(int x) {
  int res = 1;
  for (; x > 0; x -= (x & -x)) res = 1LL * res * f[x] % mod;
  return res;
}
void xl() {
  for (int i = n; i >= 1; i--) {
    ud(i, a[i]);
    for (int j = a[i]; j > 1; j /= div1[j]) {
      int d = div1[j];
      if (id[d] == i) continue;
      int x = 1LL * (d - 1) * up[d] % mod;
      int y = 1LL * d * up[d - 1] % mod;
      if (id[d]) ud(id[d], y);
      id[d] = i;
      ud(i, x);
    }
    for (int k = kt[i]; k > 0; k = BIT[k].l) ans[k] = query(BIT[k].r);
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  nhap();
  init();
  xl();
  return 0;
}
