#include <bits/stdc++.h>
using namespace std;
int primos[1000005];
int D[200005];
int n, q;
vector<pair<pair<int, int>, int> > queries;
vector<int> p[200005];
map<int, deque<int> > M;
vector<pair<int, int> > sol;
void sieve() {
  for (int i = 0; i < (int)1000001; i++) primos[i] = i;
  for (int i = 2; i * i < 1000001; i++) {
    if (primos[i] == i) {
      for (int j = i * i; j <= 1000001; j += i) {
        primos[j] = i;
      }
    }
  }
}
void fact(int x, int idx) {
  while (x != 1) {
    M[primos[x]].push_back(idx);
    p[idx].push_back(primos[x]);
    int &pri = primos[x];
    while ((x % pri) == 0) x /= pri;
  }
}
long long tree[800020];
long long op(long long a, long long b) { return (a * b % 1000000007LL); }
void build(int node, int a, int b) {
  if (a > b) return;
  if (a == b) {
    tree[node] = D[a];
    return;
  }
  build(node << 1, a, (a + b) >> 1);
  build(node << 1 | 1, 1 + ((a + b) >> 1), b);
  tree[node] = op(tree[node << 1], tree[node << 1 | 1]);
}
void update(int node, int a, int b, int idx, int val1, int val2) {
  if (idx < a || idx > b) return;
  if (a == b) {
    tree[node] = ((tree[node] / val2) * val1) % 1000000007LL;
    return;
  } else {
    int m = (a + b) >> 1;
    if (idx <= m)
      update(node << 1, a, m, idx, val1, val2);
    else
      update(node << 1 | 1, m + 1, b, idx, val1, val2);
    tree[node] = op(tree[node << 1], tree[node << 1 | 1]);
  }
}
int query(int node, int a, int b, int l, int r) {
  if (a > r || b < l) {
    return 1;
  }
  if (l <= a && b <= r) {
    return tree[node];
  }
  int m = (a + b) >> 1;
  int q1 = query(node << 1, a, m, l, r);
  int q2 = query(node << 1 | 1, m + 1, b, l, r);
  return op(q1, q2);
}
int que(int x, int y) { return query(1, 1, n, x, y); }
void up(int idx, int val1, int val2) { update(1, 1, n, idx, val1, val2); }
void go() {
  sieve();
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    cin >> D[i + 1];
    fact(D[i + 1], i + 1);
  }
  cin >> q;
  for (int i = 0; i < (int)q; i++) {
    int x, y;
    cin >> x >> y;
    queries.push_back({{x, y}, i + 1});
  }
  sort((queries).begin(), (queries).end());
  build(1, 1, n);
  for (auto it = M.begin(); it != M.end(); it++) {
    up((it->second).front(), (it->first) - 1, (it->first));
  }
  int fl = 1;
  for (auto qu : queries) {
    int &x = qu.first.first;
    int &y = qu.first.second;
    int &idx = qu.second;
    if (fl < x) {
      for (int i = fl; i < (int)x; i++) {
        for (auto j : p[i]) {
          M[j].pop_front();
          if (!M[j].empty()) {
            up(M[j].front(), j - 1, j);
          }
        }
      }
      fl = x;
    }
    sol.push_back({idx, que(x, y)});
  }
  sort((sol).begin(), (sol).end());
  for (auto i : sol) {
    cout << i.second << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  go();
  return 0;
}
