#include <bits/stdc++.h>
using namespace std;
struct Query {
  int l, r, id;
  bool operator<(const Query& other) const { return l < other.l; }
};
const int MOD = 1000000000 + 7;
long long div(long long n) {
  long long r = 1, p = MOD - 2;
  while (p) {
    if (p & 1) r = (r * n) % MOD;
    n = (n * n) % MOD;
    p >>= 1;
  }
  return r;
}
void st_set(int v, int l, int r, int ind, int val, vector<long long>& st) {
  if (l == r) {
    st[v] = (st[v] * val) % MOD;
  } else {
    int m = (l + r) / 2;
    if (ind <= m)
      st_set(v + v, l, m, ind, val, st);
    else
      st_set(v + v + 1, m + 1, r, ind, val, st);
    st[v] = (st[v + v] * st[v + v + 1]) % MOD;
  }
}
long long st_get(int v, int l, int r, int tl, int tr, vector<long long>& st) {
  if (l == tl && r == tr) return st[v];
  long long res = 1;
  int m = (l + r) / 2;
  if (tl <= m) res = st_get(v + v, l, m, tl, min(tr, m), st);
  if (tr > m)
    res = (res * st_get(v + v + 1, m + 1, r, max(m + 1, tl), tr, st)) % MOD;
  return res;
}
int main() {
  const int MAXVAL = 1000000 + 1;
  vector<int> sieve(MAXVAL);
  for (int i = 0; i < MAXVAL; i++) sieve[i] = i;
  for (int j = 2; j * j < MAXVAL; j++) {
    if (sieve[j] == j) {
      for (int i = j * j; i < MAXVAL; i += j) sieve[i] = j;
    }
  }
  int n;
  scanf("%d", &n);
  vector<vector<int>> numbers(n);
  vector<int> first_indexes(MAXVAL, -1);
  vector<vector<int>> all_indexes(MAXVAL);
  vector<int> cursors(MAXVAL, 0);
  for (int i = 0; i < n; i++) {
    int value;
    scanf("%d", &value);
    while (value != 1) {
      int d = sieve[value];
      numbers[i].push_back(d);
      value /= d;
      if (first_indexes[d] == -1) first_indexes[d] = i;
      all_indexes[d].push_back(i);
    }
    sort(numbers[i].begin(), numbers[i].end());
  }
  vector<long long> pows(MAXVAL, 0), adds(n);
  long long add = 1;
  for (int i = 0; i < n; i++) {
    for (int p : numbers[i]) {
      add = (add * p) % MOD;
    }
    adds[i] = add;
  }
  int m;
  scanf("%d", &m);
  vector<Query> qs(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &qs[i].l, &qs[i].r);
    qs[i].id = i;
    --qs[i].l, --qs[i].r;
  }
  sort(qs.begin(), qs.end());
  vector<long long> st1(4 * n, 1);
  vector<long long> st2(4 * n, 1);
  for (int i = 0; i < MAXVAL; i++) {
    if (first_indexes[i] != -1) {
      st_set(1, 0, n - 1, first_indexes[i], i - 1, st1);
      st_set(1, 0, n - 1, first_indexes[i], i, st2);
    }
  }
  vector<long long> results(m, 0);
  int cursor = 0;
  for (int l = 0; l < n; l++) {
    while (cursor < qs.size() && qs[cursor].l == l) {
      auto q = qs[cursor++];
      long long res = adds[q.r];
      if (q.l > 0) res = (res * div(adds[q.l - 1])) % MOD;
      res = (res * st_get(1, 0, n - 1, q.l, q.r, st1)) % MOD;
      res = (res * div(st_get(1, 0, n - 1, q.l, q.r, st2))) % MOD;
      results[q.id] = res;
    }
    numbers[l].erase(unique(numbers[l].begin(), numbers[l].end()),
                     numbers[l].end());
    for (int d : numbers[l]) {
      auto& indexes = all_indexes[d];
      while (cursors[d] < indexes.size() && indexes[cursors[d]] == l) {
        ++cursors[d];
      }
      if (cursors[d] < indexes.size()) {
        st_set(1, 0, n - 1, indexes[cursors[d]], d - 1, st1);
        st_set(1, 0, n - 1, indexes[cursors[d]], d, st2);
      }
    }
  }
  for (int i = 0; i < int(m); ++i) {
    printf("%lld\n", results[i]);
  }
  return 0;
}
