#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
const int AI = 1000001;
int arr[N];
int inv0[AI];
int inv1[AI];
long long int cummul[N];
int q, l, r, n;
int SQRT;
const int SIEVE_LIMIT = AI;
int lp[SIEVE_LIMIT + 1];
vector<pair<int, int> > Q[1000001];
vector<int> uniqueFactors[AI];
int answers[AI];
long long int power(long long int base, long long int exp, long long int md) {
  if (exp == 0) return 1LL;
  long long int root = power(base, exp / 2, md);
  if (exp & 1LL) return (((root * root) % md) * base) % md;
  return (root * root) % md;
}
class BIT {
 public:
  long long int *tree, N;
  BIT(long long int LOGSZ) {
    tree = new long long int[(1 << LOGSZ) + 1];
    N = (1 << LOGSZ);
    for (int i = 0; i <= N; i++) {
      tree[i] = 1LL;
    }
  }
  void update(long long int x, long long int v) {
    while (x <= N) {
      tree[x] = (tree[x] * v) % 1000000007LL;
      x += (x & -x);
    }
  }
  long long int get(long long int x) {
    int res = 1LL;
    while (x) {
      res = (res * tree[x]) % 1000000007LL;
      x -= (x & -x);
    }
    return res;
  }
  int getind(int x) {
    int idx = 0, mask = N;
    while (mask && idx < N) {
      int t = idx + mask;
      if (x >= tree[t]) {
        idx = t;
        x -= tree[t];
      }
      mask >>= 1;
    }
    return idx;
  }
  long long int rangequery(long long int l, long long int r) {
    return (get(r) * power(get(l - 1), 1000000007LL - 2, 1000000007LL)) %
           1000000007LL;
  }
};
BIT B(20);
long long int inv(long long int x) {
  return power(x, 1000000007LL - 2, 1000000007LL);
}
vector<int> pr;
void linear_sieve() {
  for (int i = 2; i <= SIEVE_LIMIT; i++) {
    if (lp[i] == 0) {
      lp[i] = i;
      inv0[i] = inv(i);
      inv1[i] = inv(i - 1);
      pr.push_back(i);
    }
    for (int j = 0;
         j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= SIEVE_LIMIT; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
void addFactors(int num) {
  int orignalNum = num;
  while (num != 1) {
    int lprime = lp[num];
    while (num % lprime == 0) {
      num = num / lprime;
    }
    uniqueFactors[orignalNum].push_back(lprime);
  }
}
long long int rangeproduct(int l, int r) {
  if (l == 1) return cummul[r];
  return (cummul[r] * inv(cummul[l - 1])) % 1000000007LL;
}
int lastLocations[1000001];
int main() {
  fill(lastLocations, lastLocations + 1000001, -1);
  linear_sieve();
  scanf("%d", &n);
  SQRT = sqrt(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", arr + i);
    if (uniqueFactors[arr[i]].size() == 0) addFactors(arr[i]);
    cummul[i] = (i == 1) ? arr[i] : (arr[i] * cummul[i - 1]) % 1000000007LL;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &l, &r);
    Q[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < uniqueFactors[arr[i]].size(); j++) {
      int pr = uniqueFactors[arr[i]][j];
      B.update(i, ((long long int)(pr - 1) * (long long int)inv0[pr]) %
                      1000000007LL);
      if (lastLocations[pr] != -1) {
        B.update(lastLocations[pr],
                 ((long long int)inv1[pr] * (long long int)pr) % 1000000007LL);
      }
      lastLocations[pr] = i;
    }
    for (int j = 0; j < Q[i].size(); j++) {
      answers[Q[i][j].second] =
          (B.rangequery(Q[i][j].first, i) * rangeproduct(Q[i][j].first, i)) %
          1000000007LL;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << answers[i] << endl;
  }
  return 0;
}
