#include <bits/stdc++.h>
using namespace std;
const int lim = 1e6;
bool flag[lim + 5];
int p[lim + 5], num;
int minp[lim + 5];
int n, x[200005];
int dqx, now;
vector<int> v[200005];
vector<int> vx[lim + 5];
struct Node {
  int l, r, id;
  bool operator<(const Node &a) const { return l < a.l; }
} f[200005];
int ans[200005];
int ny[lim + 5];
const int mod = 1e9 + 7;
int c[200005];
int m, dq;
int lowbit(int x) { return x & (-x); }
void add(int x, int y) {
  for (int i = x; i <= n; i += lowbit(i)) {
    c[i] = 1LL * c[i] * y % mod;
  }
}
int query(int x) {
  int ans = 1;
  for (int i = x; i >= 1; i -= lowbit(i)) {
    ans = 1LL * c[i] * ans % mod;
  }
  return ans;
}
int powmod(int a, int b, int c) {
  int ans = 1;
  while (b) {
    if (b % 2 == 1) ans = 1LL * ans * a % c;
    b /= 2;
    a = 1LL * a * a % c;
  }
  return ans;
}
void prework() {
  memset(flag, true, sizeof(flag));
  flag[0] = flag[1] = false;
  num = 0;
  for (int i = 2; i <= lim; ++i) {
    if (flag[i]) {
      ++num;
      p[num] = i;
      minp[i] = num;
    }
    for (int j = 1; j <= num; ++j) {
      if (i * p[j] > lim) break;
      flag[i * p[j]] = false;
      minp[i * p[j]] = j;
      if (i % p[j] == 0) break;
    }
  }
}
int main() {
  prework();
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
  for (int i = 1; i <= n; ++i) {
    v[i].clear();
    dqx = x[i];
    while (dqx != 1) {
      v[i].push_back(minp[dqx]);
      vx[minp[dqx]].push_back(i);
      now = minp[dqx];
      while (minp[dqx] == now) dqx /= p[now];
    }
  }
  for (int i = 1; i <= num; ++i) reverse(vx[i].begin(), vx[i].end());
  memset(c, 0, sizeof(c));
  for (int i = 1; i <= lim; ++i) ny[i] = powmod(i, mod - 2, mod);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &f[i].l, &f[i].r);
    f[i].id = i;
  }
  sort(f + 1, f + m + 1);
  for (int i = 1; i <= n; ++i) c[i] = 1;
  for (int i = 1; i <= n; ++i) {
    add(i, x[i]);
    for (int j = 0; j < v[i].size(); ++j) {
      if (vx[v[i][j]].back() == i)
        add(i, 1LL * (p[v[i][j]] - 1) * ny[p[v[i][j]]] % mod);
    }
  }
  dq = 1;
  for (int i = 1; i <= n; ++i) {
    while (dq <= m && f[dq].l == i) {
      ans[f[dq].id] = query(f[dq].r);
      ++dq;
    }
    add(i, ny[x[i]]);
    for (int j = 0; j < v[i].size(); ++j) {
      add(i, 1LL * p[v[i][j]] * ny[p[v[i][j]] - 1] % mod);
      vx[v[i][j]].pop_back();
      if (vx[v[i][j]].size() > 0) {
        add(vx[v[i][j]].back(), 1LL * (p[v[i][j]] - 1) * ny[p[v[i][j]]] % mod);
      }
    }
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << endl;
  return 0;
}
