#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
inline void solve(), read();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  solve();
  return 0;
}
const long long MAXN = 1e6 + 10;
const long long R = 1e9 + 7;
bool comp[MAXN];
vector<long long> fact[MAXN];
void sieve() {
  for (long long i = 2; i < MAXN; i++) {
    if (comp[i]) {
      continue;
    }
    for (long long j = i; j < MAXN; j += i) {
      comp[j] = 1;
      fact[j].push_back(i);
    }
  }
}
long long binpow(long long n, long long p) {
  if (p == 0) return 1;
  if (p == 1) return n;
  long long a = binpow(n, p / 2);
  a = a * a % R;
  if (p % 2 == 1) {
    a = a * n % R;
  }
  return a;
}
long long inv(long long n) { return binpow(n, R - 2); }
struct fenwick {
  long long n;
  vector<long long> t;
  fenwick() {}
  fenwick(long long n_) {
    n = n_;
    t.resize(n, 1);
  }
  long long f(long long i) { return i & (i + 1); }
  long long h(long long i) { return i | (i + 1); }
  void upd(long long ind, long long d) {
    for (long long i = ind; i < n; i = h(i)) {
      t[i] *= d;
      t[i] %= R;
    }
  }
  long long sum(long long ind) {
    long long ans = 1;
    for (long long i = ind; i >= 0; i = f(i) - 1) {
      ans *= t[i];
      ans %= R;
    }
    return ans;
  }
};
long long n, q;
vector<long long> a, l, r, ind, ans;
vector<long long> pos[MAXN];
fenwick f;
void precalc() {
  for (long long i = 0; i < n; i++) {
    for (long long x : fact[a[i]]) {
      pos[x].push_back(i);
    }
  }
  for (long long i = 2; i < MAXN; i++) {
    if (!pos[i].empty()) {
      reverse((pos[i]).begin(), (pos[i]).end());
      long long val = (i - 1) * inv(i) % R;
      f.upd(pos[i].back(), val);
      pos[i].pop_back();
    }
  }
}
bool com(long long i, long long j) {
  if (l[i] != l[j]) {
    return l[i] < l[j];
  }
  return r[i] < r[j];
}
void move(long long l) {
  for (long long x : fact[a[l]]) {
    long long val = x * inv(x - 1) % R;
    f.upd(l, val);
    if (!pos[x].empty()) {
      val = (x - 1) * inv(x) % R;
      f.upd(pos[x].back(), val);
      pos[x].pop_back();
    }
  }
  long long val = inv(a[l]);
  f.upd(l, val);
}
inline void solve() {
  f = fenwick(n);
  for (long long i = 0; i < n; i++) {
    f.upd(i, a[i]);
  }
  sieve();
  precalc();
  ans.resize(q);
  ind.resize(q);
  iota((ind).begin(), (ind).end(), 0);
  sort((ind).begin(), (ind).end(), com);
  long long cl = 0;
  for (long long i : ind) {
    long long l = ::l[i], r = ::r[i];
    while (cl < l) {
      move(cl);
      ++cl;
    }
    long long cur = f.sum(r);
    ans[i] = cur;
  }
  for (long long i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
}
inline void read() {
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  l.resize(q), r.resize(q);
  for (long long i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
    --l[i], --r[i];
  }
}
