#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void si(T &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c<48 | c> 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }
void io() { freopen("/Users/MyMac/Desktop/in.txt", "r", stdin); }
const int N = 2e5 + 5;
const int MX = 1e6 + 6;
long long MOD = 1e9 + 7;
long long a[N];
vector<pair<int, int> > G[N];
vector<int> Prime;
vector<int> L[MX];
bool vis[MX];
void seive() {
  for (int i = 2; i < MX; i++) {
    if (vis[i] == 0) {
      L[i].push_back((i));
      Prime.push_back((i));
      for (int j = 2; i * j < MX; j++) {
        L[i * j].push_back((i));
        vis[i * j] = 1;
      }
    }
  }
}
int pos[MX];
vector<pair<int, int> > nxt[N];
long long ib[N];
void update(int x, long long val) {
  while (x < N) {
    ib[x] *= val;
    ib[x] %= MOD;
    x += x & -x;
  }
}
long long ans[N];
long long query(int x) {
  long long r = 1;
  for (; x > 0; x -= x & -x) {
    r *= ib[x];
    r %= MOD;
  }
  return r;
}
int main() {
  seive();
  int n;
  si(n);
  for (int i = 1; i <= n; i++) {
    si(a[i]);
  }
  for (int i = 0; i < MX; i++) pos[i] = n + 1;
  for (int i = n; i > 0; i--) {
    for (auto k : L[a[i]]) {
      nxt[i].push_back((make_pair(k, pos[k])));
      pos[k] = i;
    }
  }
  for (int i = 0; i < n + 1; i++) ib[i] = 1;
  for (int i = 1; i <= n; i++) update(i, a[i]);
  for (auto a : Prime) {
    int posi = pos[a];
    if (posi <= n) {
      long long u = ((a - 1) * modinverse(a, MOD)) % MOD;
      update(posi, u);
    }
  }
  int q;
  si(q);
  for (int i = 0; i < q; i++) {
    int a, b;
    si(a);
    si(b);
    G[a].push_back((make_pair(b, i)));
  }
  for (int i = 1; i <= n; i++) {
    for (auto a : G[i]) {
      int R = a.first, ind = a.second;
      ans[ind] = query(R);
    }
    update(i, modinverse(a[i], MOD));
    for (int u = 0; u < L[a[i]].size(); u++) {
      long long pp = L[a[i]][u];
      long long up = (pp * modinverse(pp - 1, MOD)) % MOD;
      update(i, up);
      int neid = nxt[i][u].second;
      if (neid <= n) {
        up = ((pp - 1) * modinverse(pp, MOD)) % MOD;
        update(neid, up);
      }
    }
  }
  for (int i = 0; i < q; i++) printf("%lld\n", ans[i]);
  return 0;
}
