#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
const int maxn = (int)1e6 + 5;
const int INF = 1e9 + 7;
const double eps = 1e-8;
vector<int> prime;
int p[1001];
void sieve() {
  for (int i = 2; i <= 1000; i++) {
    if (p[i]) continue;
    prime.push_back(i);
    for (int j = i * i; j <= 1000; j += i) {
      p[j] = 1;
    }
  }
  return;
}
long long modpow(long long x, long long expo) {
  if (expo == 0) return 1;
  long long y = modpow(x, expo / 2);
  y = (y * y) % 1000000007;
  if (expo % 2 == 1) {
    y = (y * x) % 1000000007;
  }
  return y;
}
struct BIT {
  long long t[maxn + 6];
  BIT(void) {
    for (int i = (0); i < (maxn + 6); i++) t[i] = 1;
  }
  void set(int i, long long v) {
    for (; i <= 1000000; i += i & -i) t[i] = (t[i] * v) % 1000000007;
  }
  long long get(int i) {
    if (i == 0) return 1;
    long long s = 1;
    for (; i; i -= i & -i) s = (s * t[i]) % 1000000007;
    return s;
  }
  long long rangeQuery(int l, int r) {
    return (get(r) * modpow(get(l - 1), 1000000007 - 2)) % 1000000007;
  }
};
int a[maxn], lst[maxn];
long long allNum[maxn];
long long res[maxn], ans[maxn], inv[maxn];
vector<pair<int, int> > q1[maxn];
vector<int> fact[maxn];
inline void solve(void) {
  sieve();
  int n;
  scanf("%d", &n);
  allNum[0] = 1;
  for (int i = (0); i < (prime.size()); i++)
    inv[prime[i]] = modpow(prime[i], 1000000007 - 2),
    inv[prime[i] - 1] = modpow(prime[i] - 1, 1000000007 - 2);
  for (int i = (0); i < (n); i++) {
    scanf("%d", &a[i]);
    allNum[i + 1] = (allNum[i] * 1LL * a[i]) % 1000000007;
    int get = a[i];
    for (int j = (0); j < (prime.size()); j++) {
      if (get % prime[j] == 0) {
        fact[i + 1].push_back(prime[j]);
        while (get % prime[j] == 0) get /= prime[j];
      }
    }
    if (get > 1)
      fact[i + 1].push_back(get),
          inv[get] = modpow(get, 1000000007 - 2),
          inv[get - 1] = modpow(get - 1, 1000000007 - 2);
  }
  int q, x, y;
  cin >> q;
  int q11 = q;
  int qNum = 1;
  while (q--) {
    scanf("%d", &x);
    scanf("%d", &y);
    long long ans1 = 1;
    ans1 = (ans1 * allNum[y]) % 1000000007;
    ans1 = (ans1 * modpow(allNum[x - 1], 1000000007 - 2)) % 1000000007;
    ans[qNum] = ans1;
    q1[y].push_back(make_pair(x, qNum));
    qNum++;
  }
  BIT t1;
  for (int i = 1; i <= n; i++) {
    for (int x : fact[i]) {
      if (lst[x] != 0) {
        t1.set(lst[x], x);
        t1.set(lst[x], inv[x - 1]);
      }
      t1.set(i, x - 1);
      t1.set(i, inv[x]);
      lst[x] = i;
    }
    for (int j = (0); j < (q1[i].size()); j++) {
      ans[q1[i][j].second] =
          (ans[q1[i][j].second] * t1.rangeQuery(q1[i][j].first, i)) %
          1000000007;
    }
  }
  for (int i = (1); i < (q11 + 1); i++) printf("%d\n", (int)ans[i]);
  ;
  return;
}
void init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
int main(int argc, const char *argv[]) {
  solve();
  return 0;
}
