#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
  ostringstream str;
  str << a;
  return str.str();
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
const int N = 1e6 + 10;
vector<int> prime;
int primeFrac[N], invPrimeFrac[N];
namespace MOs_Algorithm {
const int maxn = 2e5 + 10, block_size = 500;
struct info {
  int l, r, idx;
  info() {}
  info(int x, int y, int z) { l = x, r = y, idx = z; }
} v[maxn];
int n, m, cnt[N], res[maxn], ar[maxn], inv_Ar[maxn];
long long nn = 1;
vector<int> a[maxn];
inline void Add_Right(int l, int r) {
  while (l <= r) {
    nn = nn * ar[l] % 1000000007LL;
    for (const auto &p : a[l]) {
      if (!cnt[p]) {
        nn = nn * primeFrac[p] % 1000000007LL;
      }
      cnt[p]++;
    }
    l++;
  }
}
inline void Add_Left(int l, int r) { Add_Right(l, r); }
inline void Remove_Left(int l, int r) {
  while (l <= r) {
    nn = nn * inv_Ar[l] % 1000000007LL;
    for (const auto &p : a[l]) {
      cnt[p]--;
      if (!cnt[p]) {
        nn = nn * invPrimeFrac[p] % 1000000007LL;
      }
    }
    l++;
  }
}
inline void Remove_Right(int l, int r) { Remove_Left(l, r); }
inline void MOs() {
  if (!m) return;
  sort(v, v + m, [&](const info &A, const info &B) {
    return (A.l / block_size) == (B.l / block_size)
               ? A.r < B.r
               : (A.l / block_size) < (B.l / block_size);
  });
  int ovl, ovr, l = 1, r = -1;
  for (int i = int(0); i < int(m); i++) {
    const auto &q = v[i];
    ovl = max(l, q.l);
    ovr = min(r, q.r);
    if (ovl <= ovr) {
      if (l < q.l) Remove_Left(l, q.l - 1);
      if (l > q.l) Add_Left(q.l, l - 1);
      if (r < q.r) Add_Right(r + 1, q.r);
      if (r > q.r) Remove_Right(q.r + 1, r);
    } else
      Remove_Right(l, r), Add_Left(q.l, q.r);
    l = q.l, r = q.r;
    res[q.idx] = nn;
  }
}
}  // namespace MOs_Algorithm
using namespace MOs_Algorithm;
bool b[N];
inline void Siv() {
  prime.push_back(2);
  primeFrac[2] = modInverse(2LL, 1000000007LL);
  invPrimeFrac[2] = 2;
  for (long long i = 3; i < N; i += 2) {
    if (!b[i]) {
      prime.push_back(i);
      primeFrac[i] = (i - 1) * modInverse(i, 1000000007LL) % 1000000007LL;
      invPrimeFrac[i] = i * modInverse(i - 1, 1000000007LL) % 1000000007LL;
      if (i * i < N)
        for (long long j = i * i; j < N; j += i << 1) b[j] = 1;
    }
  }
}
inline void Fact(int n, vector<int> &ret) {
  for (const long long &p : prime) {
    if (p * p > n) break;
    if (n % p == 0) {
      int cnt = 0;
      while (n % p == 0) n /= p, cnt++;
      ret.push_back(p);
    }
  }
  if (n > 1) ret.push_back(n);
}
int main() {
  Siv();
  int x, y;
  scanf("%d", &n);
  for (int i = int(0); i < int(n); i++)
    scanf("%d", &ar[i]), Fact(ar[i], a[i]),
        inv_Ar[i] = modInverse((long long)ar[i], 1000000007LL);
  scanf("%d", &m);
  for (int i = int(0); i < int(m); i++) {
    scanf("%d%d", &x, &y), x--, y--;
    v[i] = info(x, y, i);
  }
  MOs();
  for (int i = int(0); i < int(m); i++) printf("%d\n", res[i]);
  return 0;
}
