#include <bits/stdc++.h>
using namespace std;
class question {
 public:
  int l, r, i;
};
const long long mod = 1e9 + 7;
long long pwr(const long long& a, const long long& b) {
  if (!b) return 1;
  long long m = pwr(a, (b >> 1ll));
  m = (m * m) % mod;
  if (b & 1) m = (m * a) % mod;
  return m;
}
const int maxn = 2e5 + 79, maxa = 1e6 + 79;
vector<long long> st(maxn * 2, 1);
void update(int l, int r, long long val) {
  for (l += maxn, r += maxn + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      st[l] = (st[l] * val) % mod;
      l++;
    }
    if (r & 1) {
      r--;
      st[r] = (st[r] * val) % mod;
    }
  }
}
long long query(int i) {
  long long ans = 1;
  for (i += maxn; i > 0; i >>= 1) ans = (ans * st[i]) % mod;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<long long> ans(q, 0);
  vector<vector<question> > qu(n);
  for (int i = 0; i < q; i++) {
    question qq;
    cin >> qq.l >> qq.r;
    qq.l--;
    qq.r--;
    qq.i = i;
    qu[qq.r].push_back(qq);
  }
  vector<int> last(maxa, -1);
  for (int i = 0; i < n; i++) {
    update(0, i, a[i]);
    vector<int> p;
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        p.push_back(j);
        for (; a[i] % j == 0; a[i] /= j)
          ;
      }
    }
    if (a[i] > 1) p.push_back(a[i]);
    for (int pr : p) {
      long long val = ((pr - 1ll) * 1ll * pwr(pr, mod - 2)) % mod;
      update(last[pr] + 1, i, val);
      last[pr] = i;
    }
    for (question& qq : qu[i]) ans[qq.i] = query(qq.l);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
