#include <bits/stdc++.h>
using namespace std;
int P[1000005], a[200005], num[1000005], Up[1000005], Down[1000005], n, q, sq,
    res[200005], oo = 1e9 + 7;
long long Sum[200005], ans = 1;
pair<pair<int, int>, int> que[200005];
vector<int> Div[1000005];
long long Pow(int x, int y) {
  long long r = 1;
  while (y) {
    if (y & 1) r = r * x % oo;
    x = 1ll * x * x % oo;
    y >>= 1;
  }
  return r;
}
void PUSH(int x) {
  for (int i = 0; i < Div[x].size(); i++) {
    int u = Div[x][i];
    num[u]++;
    if (num[u] == 1) ans = ans * Up[u] % oo;
  }
}
void POP(int x) {
  for (int i = 0; i < Div[x].size(); i++) {
    int u = Div[x][i];
    num[u]--;
    if (num[u] == 0) ans = ans * Down[u] % oo;
  }
}
bool cmp(pair<pair<int, int>, int> X, pair<pair<int, int>, int> Y) {
  if (X.first.first / sq != Y.first.first / sq)
    return X.first.first / sq < Y.first.first / sq;
  return X.first.second < Y.first.second;
}
int main() {
  int x, u;
  cin >> n;
  for (int i = 2; i < 1000005; i++) {
    if (P[i]) continue;
    Up[i] = Pow(i, oo - 2) * (i - 1) % oo;
    Down[i] = Pow(i - 1, oo - 2) * i % oo;
    for (int j = i; j < 1000005; j += i) P[j] = i;
  }
  Sum[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    Sum[i] = Sum[i - 1] * x % oo;
    while (x > 1) {
      u = P[x];
      while (x % u == 0) x /= u;
      Div[i].push_back(u);
    }
  }
  cin >> q;
  sq = 500;
  for (int i = 1; i <= q; i++)
    scanf("%d%d", &que[i].first.first, &que[i].first.second), que[i].second = i;
  sort(que + 1, que + q + 1, cmp);
  int l = 0;
  int r = 0;
  for (int i = 1; i <= q; i++) {
    while (l < que[i].first.first) {
      POP(l);
      l++;
    }
    while (l > que[i].first.first) {
      PUSH(l - 1);
      l--;
    }
    while (r > que[i].first.second) {
      POP(r);
      r--;
    }
    while (r < que[i].first.second) {
      PUSH(r + 1);
      r++;
    }
    res[que[i].second] = Sum[r] * Pow(Sum[l - 1], oo - 2) % oo * ans % oo;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", res[i]);
}
