#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 70;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 1000;
long long pw(long long a, long long n) {
  if (n == 0) return 1;
  long long b = pw(a, n >> 1);
  b = (b * b) % mod;
  if (n & 1) {
    b = b * a % mod;
  }
  return b;
}
long long c[maxn];
int ql[maxn];
int qr[maxn];
long long ans[maxn];
long long FT[maxn];
int lsone(int p) { return p & (-p); }
void update(int i, long long lambda) {
  for (int p = i; p < maxn; p += lsone(p)) {
    FT[p] = (FT[p] * lambda) % mod;
  }
}
long long sum(int i) {
  long long ans = 1;
  for (int p = i; p > 0; p -= lsone(p)) {
    ans = (ans * FT[p]) % mod;
  }
  return ans;
}
long long val(long long p) { return (p - 1) * pw(p, mod - 2) % mod; }
bool composite[1000];
vector<int> here[maxn];
int main() {
  for (int i = (0); i < (maxn); i++) {
    FT[i] = 1;
  }
  for (int p = 2; p * p < 1000; p++) {
    if (composite[p]) continue;
    for (int q = p * p; q < 1000; q += p) {
      composite[q] = true;
    }
  }
  if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin);
  int(n);
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d", &(c[i]));
    update(i, c[i]);
  }
  int(q);
  scanf("%d", &q);
  for (int query = (0); query < (q); query++) {
    scanf("%d%d", &(ql[query]), &(qr[query]));
    ans[query] = sum(qr[query]) * pw(sum(ql[query] - 1), mod - 2) % mod;
  }
  for (int p = (2); p < (1000); p++) {
    if (composite[p]) continue;
    vector<int> w(n + 1);
    for (int i = (1); i < (n + 1); i++) {
      if (c[i] % p == 0) {
        w[i]++;
      }
      while (c[i] % p == 0) c[i] /= p;
    }
    long long v = val(p);
    for (int i = (1); i < (n + 1); i++) {
      w[i] += w[i - 1];
    }
    for (int query = (0); query < (q); query++) {
      if (w[qr[query]] - w[ql[query] - 1] >= 1) {
        ans[query] = (ans[query] * v) % mod;
      }
    }
  }
  for (int i = (0); i < (maxn); i++) {
    FT[i] = 1;
  }
  for (int query = (0); query < (q); query++) {
    here[qr[query]].push_back(query);
  }
  unordered_map<int, int> lastseen;
  for (int i = (1); i < (n + 1); i++) {
    if (c[i] != 1) {
      long long v = val(c[i]);
      int p = lastseen[c[i]];
      if (p != 0) {
        update(p, pw(v, mod - 2));
      }
      update(i, v);
      lastseen[c[i]] = i;
    }
    for (int query : here[i]) {
      ans[query] = (ans[query] * sum(i)) % mod;
      ans[query] = (ans[query] * pw(sum(ql[query] - 1), mod - 2)) % mod;
    }
  }
  for (int query = (0); query < (q); query++) {
    cout << ans[query] << "\n";
  }
  return 0;
}
