#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
vector<long long int> fvc;
long long int mod = 1000000007;
void mltp(int i, int val) {
  for (i++; i < fvc.size(); i += i & (-i)) fvc[i] = fvc[i] * val % mod;
}
int res(int i) {
  long long int rez = 1;
  for (i++; i > 0; i -= i & (-i)) rez = rez * fvc[i] % mod;
  return rez;
}
long long int modinv(long long int num) {
  int b = mod - 2;
  long long int rez = 1;
  while (b) {
    if (b % 2) rez = rez * num % mod;
    num = num * num % mod;
    b /= 2;
  }
  return rez;
}
int main() {
  ios::sync_with_stdio(false);
  int n, q;
  vector<int> prv(1000001, -1);
  vector<long long int> pr;
  for (int i = 2, prime = true; i < 1000; i++, prime = true) {
    for (int j = 0; j < pr.size() && pr[j] * pr[j] <= i; j++) {
      if (i % pr[j]) continue;
      prime = false;
      break;
    }
    if (prime) pr.push_back(i);
  }
  cin >> n;
  v.resize(n);
  fvc.resize(n + 1, 1);
  for (int i = 0; i < n; i++) cin >> v[i];
  cin >> q;
  vector<long long int> que(q);
  vector<vector<pair<int, int> > > ord(n);
  for (int i = 0, l, r; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    ord[r].push_back({i, l});
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0, c = 0; j < pr.size() && pr[j] * pr[j] <= v[i]; j++, c = 0) {
      while (v[i] % pr[j] == 0) {
        v[i] /= pr[j];
        c++;
      }
      if (!c) continue;
      if (prv[pr[j]] != -1) mltp(prv[pr[j]], pr[j] * modinv(pr[j] - 1) % mod);
      prv[pr[j]] = i;
      mltp(i, pr[j] - 1);
      while (--c) mltp(i, pr[j]);
    }
    if (v[i] > 1) {
      if (prv[v[i]] != -1) mltp(prv[v[i]], v[i] * modinv(v[i] - 1) % mod);
      prv[v[i]] = i;
      mltp(i, v[i] - 1);
    }
    for (int j = 0; j < ord[i].size(); j++) {
      int ind = ord[i][j].first;
      que[ind] = res(i);
      if (ord[i][j].second)
        que[ind] = que[ind] * modinv(res(ord[i][j].second - 1)) % mod;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << que[i] << endl;
  }
}
