#include <bits/stdc++.h>
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
inline int read() {
  static char ch;
  bool sgn = false;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') sgn = true;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return sgn ? -res : res;
}
const int N = 2e5 + 5, M = 1e6 + 1;
const int mod = 1e9 + 7;
int n, m, a[N], l[N], r[N], p[N];
int f[N], ans[N];
int tot, pri[N], min[M], first[M];
bool isp[M];
inline bool cmp(const int &x, const int &y) { return r[x] < r[y]; }
inline int fpm(long long x, int Exp) {
  long long res = 1;
  for (; Exp > 0; x = x * x % mod, Exp >>= 1)
    if (Exp & 1) res = res * x % mod;
  return res;
}
inline void prime_init() {
  isp[0] = isp[1] = true;
  for (int i = 2; i < M; ++i) {
    if (!isp[i]) pri[++tot] = i, min[i] = i;
    for (int j = 1; j <= tot; ++j) {
      if (i * pri[j] >= M) break;
      isp[i * pri[j]] = true;
      min[i * pri[j]] = pri[j];
      if (i % pri[j] == 0) break;
    }
  }
}
inline void insert(int x, const int &y) {
  for (; x <= n; x += x & -x) f[x] = (long long)f[x] * y % mod;
}
inline int Query(int x) {
  int res = 1;
  for (; x > 0; x -= x & -x) res = (long long)res * f[x] % mod;
  return res;
}
inline void add(const int &x) {
  int num = a[x], tmp;
  while (num > 1) {
    tmp = min[num];
    if (first[tmp] > 0) {
      insert(first[tmp], fpm(tmp - 1, mod - 2));
      insert(first[tmp], tmp);
    }
    first[tmp] = x;
    insert(x, tmp - 1);
    num /= tmp;
  }
}
int main() {
  n = read();
  for (int i = (1); i <= (n); ++i) a[i] = read(), f[i] = 1;
  m = read();
  for (int i = (1); i <= (m); ++i) {
    l[i] = read();
    r[i] = read();
    p[i] = i;
  }
  std::sort(p + 1, p + m + 1, cmp);
  prime_init();
  int now = 0;
  for (int i = (1); i <= (m); ++i) {
    while (now < r[p[i]]) add(++now);
    ans[p[i]] =
        (long long)Query(r[p[i]]) * fpm(Query(l[p[i]] - 1), mod - 2) % mod;
  }
  for (int i = (1); i <= (m); ++i) printf("%d\n", ans[i]);
  return 0;
}
