#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const long long int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long long int N = 200000;
long long int a[N + 1];
long long int n;
vector<long long int> pr[N + 1];
long long int spf[1000001];
long long int bit[N + 1];
set<long long int> st[1000001];
void factorization() {
  long long int x, y;
  for (long long int i = 0; i < n; i++) {
    x = a[i];
    while (x > 1) {
      y = spf[x];
      st[y].insert(i + 1);
      while ((x % y) == 0) x = x / y;
      pr[i].push_back(y);
    }
  }
}
long long int getparent(long long int i) { return i - (i & (-i)); }
long long int getnext(long long int i) { return i + (i & (-i)); }
long long getproduct(long long int r) {
  long long sum = 1;
  while (r > 0) {
    sum = (sum % MOD * bit[r] % MOD) % MOD;
    r = getparent(r);
  }
  return sum;
}
void update(long long int i, long long int value) {
  while (i <= N) {
    bit[i] = (bit[i] % MOD * value % MOD) % MOD;
    i = getnext(i);
  }
}
void seive() {
  for (long long int i = 1; i <= 1000000; i++) spf[i] = i;
  for (long long int i = 2; i <= 1000; i++) {
    if (spf[i] == i)
      for (long long int j = 2 * i; j <= 1000000; j += i)
        if (spf[j] == j) spf[j] = i;
  }
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  seive();
  long long int q, l, r, x, in, value, prm;
  cin >> n;
  for (long long int i = 0; i <= N; i++) bit[i] = 1;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  factorization();
  for (long long int i = 0; i < n; i++) {
    update(i + 1, a[i]);
  }
  for (long long int i = 1; i <= 1000000; i++) {
    if (!st[i].empty()) {
      in = (*st[i].begin());
      value = ((i - 1) % MOD * power(i, MOD - 2, MOD) % MOD) % MOD;
      update(in, value);
    }
  }
  cin >> q;
  vector<pair<long long int, long long int> > query[n];
  for (long long int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    query[l].push_back(make_pair(r, i));
  }
  long long int ans[q];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < query[i].size(); j++) {
      r = query[i][j].first;
      in = query[i][j].second;
      ans[in] = getproduct(r + 1);
    }
    update(i + 1, power(a[i], MOD - 2, MOD));
    for (long long int j = 0; j < pr[i].size(); j++) {
      prm = pr[i][j];
      value = ((prm) % MOD * power(prm - 1, MOD - 2, MOD) % MOD) % MOD;
      update(i + 1, value);
      st[prm].erase(st[prm].begin());
      if (!st[prm].empty()) {
        in = (*(st[prm].begin()));
        value = ((prm - 1) % MOD * power(prm, MOD - 2, MOD) % MOD) % MOD;
        update(in, value);
      }
    }
  }
  for (long long int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
