#include <bits/stdc++.h>
using namespace std;
const int MOD = (1e9) + 7;
const int N = 1 << 18;
const int TO = 1 << 20;
struct multiplication_tree {
 private:
  int n;
  int a[N];
  int fpow(int n, int k) {
    if (n == 0) return 0;
    if (k == 0) return 1;
    int p = fpow(n, k >> 1);
    p = (p * 1ll * p) % MOD;
    if (k & 1)
      return (p * 1ll * n) % MOD;
    else
      return p;
  }
  int div_mod(int a, int b) { return (a * 1ll * fpow(b, MOD - 2)) % MOD; }

 public:
  void initialize(int k) {
    n = k;
    for (int i = 1; i <= n; i++) a[i] = 1;
  }
  void update(int pos, int val) {
    for (; pos <= n; pos += pos & (-pos)) {
      a[pos] = (a[pos] * 1ll * val) % MOD;
    }
  }
  int query(int pos) {
    int ans = 1;
    for (; pos >= 1; pos -= pos & (-pos)) {
      ans = (ans * 1ll * a[pos]) % MOD;
    }
    return ans;
  }
  int get(int from, int to) { return div_mod(query(to), query(from - 1)); }
};
int n, q, a[N];
vector<pair<int, int> > v[N];
vector<pair<int, int> > ioyhjhfajasj[N];
int aljghajkghak[TO + 5];
int partial_product[N];
int last[TO + 5];
multiplication_tree it;
int ans[N];
int sq;
bool factorized[TO + 5];
vector<int> memo[TO + 5];
int fpow(int n, int k) {
  if (n == 0) return 0;
  if (k == 0) return 1;
  int p = fpow(n, k >> 1);
  p = (p * 1ll * p) % MOD;
  if (k & 1)
    return (p * 1ll * n) % MOD;
  else
    return p;
}
int div_mod(int a, int b) { return (a * 1ll * fpow(b, MOD - 2)) % MOD; }
int get_product(int from, int to) {
  return div_mod(partial_product[to], partial_product[from - 1]);
}
vector<int> factorize(int n) {
  if (factorized[n]) return memo[n];
  vector<int> ans;
  int current_divisor, k = n;
  while (n > 1) {
    current_divisor = aljghajkghak[n];
    while (n % current_divisor == 0) {
      n /= current_divisor;
    }
    ans.push_back(current_divisor);
  }
  factorized[k] = true;
  return memo[k] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, l, r;
  vector<int> factors;
  sq = sqrt(TO);
  for (i = 2; i <= TO; i++) {
    if (aljghajkghak[i] == 0) {
      aljghajkghak[i] = i;
      if (i <= sq)
        for (j = i * i; j <= TO; j += i) {
          if (aljghajkghak[j] == 0) aljghajkghak[j] = i;
        }
    }
  }
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  partial_product[0] = 1;
  for (i = 1; i <= n; i++) {
    partial_product[i] = (partial_product[i - 1] * 1ll * a[i]) % MOD;
  }
  it.initialize(n);
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d %d", &l, &r);
    v[l].push_back(make_pair(r, i));
  }
  for (i = n; i >= 1; i--) {
    factors = factorize(a[i]);
    for (j = 0; j < (int)(factors.size()); j++) {
      if (last[factors[j]] != 0)
        ioyhjhfajasj[i].push_back(make_pair(factors[j], last[factors[j]]));
      last[factors[j]] = i;
    }
  }
  for (i = 1; i <= TO; i++) {
    if (last[i]) it.update(last[i], div_mod(i - 1, i));
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < (int)(v[i].size()); j++) {
      ans[v[i][j].second] =
          (get_product(i, v[i][j].first) * 1ll * it.get(i, v[i][j].first)) %
          MOD;
    }
    factors = factorize(a[i]);
    for (j = 0; j < (int)(factors.size()); j++) {
      it.update(i, div_mod(factors[j], factors[j] - 1));
    }
    for (j = 0; j < (int)(ioyhjhfajasj[i].size()); j++) {
      it.update(ioyhjhfajasj[i][j].second, div_mod(ioyhjhfajasj[i][j].first - 1,
                                                   ioyhjhfajasj[i][j].first));
    }
  }
  for (i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
