#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + inf;
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int mul(int x, int y) { return (long long)x * y % mod; }
inline int fe(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = mul(res, x);
    x = mul(x, x);
    k >>= 1;
  }
  return res;
}
inline int ______div(int x, int y) { return mul(x, fe(y, mod - 2)); }
int n, q;
int a[N];
vector<int> dv[N];
int val[M], invval[M], ____next[M], mind[M];
int rmul[N << 1];
pair<int, int> rng[N << 1];
vector<pair<int, int> > t[N << 1];
void add(int x, int nxt, int p) {
  x += N;
  while (x >= 1) {
    if (nxt > rng[x].second) t[x].push_back(pair<int, int>(nxt, p));
    x >>= 1;
  }
}
int getin(int x, int r) {
  int id = lower_bound(t[x].begin(), t[x].end(), pair<int, int>(r + 1, 0)) -
           t[x].begin();
  if (id < t[x].size()) return t[x][id].second;
  return 1;
}
int get(int x, int y) {
  int l = x + N, r = y + N, res = 1;
  for (; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) {
      res = mul(res, getin(l, y));
      res = mul(res, rmul[l]);
    }
    if (~r & 1) {
      res = mul(res, getin(r, y));
      res = mul(res, rmul[r]);
    }
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i < M; i++) {
    if (!mind[i]) {
      ____next[i] = n + 1;
      val[i] = add(1, mod - ______div(1, i));
      invval[i] = ______div(1, val[i]);
      for (int j = i; j < M; j += i)
        if (!mind[j]) mind[j] = i;
    }
  }
  vector<pair<pair<int, int>, int> > inits;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = n; i >= 1; i--) {
    rmul[i + N] = a[i];
    rng[i + N] = pair<int, int>(i, i);
    int x = a[i];
    while (x != 1) {
      int p = mind[x];
      dv[i].push_back(p);
      inits.push_back(make_pair(pair<int, int>(____next[p], i), p));
      ____next[p] = i;
      while (x % p == 0) x /= p;
    }
  }
  for (int i = N - 1; i >= 1; i--) {
    rmul[i] = mul(rmul[i + i], rmul[i + i + 1]);
    rng[i] = pair<int, int>(rng[i + i].first, rng[i + i + 1].second);
  }
  sort(inits.begin(), inits.end());
  for (__typeof((inits).begin()) it = (inits).begin(); it != (inits).end();
       it++) {
    int nxt = it->first.first;
    int i = it->first.second;
    int p = it->second;
    add(i, nxt, p);
  }
  for (int i = 1; i < (N << 1); i++) {
    for (int j = (int)t[i].size() - 1; j >= 0; j--) {
      int nxt = j + 1 < t[i].size() ? t[i][j + 1].second : 1;
      t[i][j].second = mul(nxt, val[t[i][j].second]);
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    int res = get(x, y);
    printf("%d\n", res);
  }
  return 0;
}
