#include <bits/stdc++.h>
using namespace std;
int n, prime[100010], pid = 0, a[233333];
long long tmp, ans[233333], inv[1000010], f[233333], g[233333],
    mul[233333 << 2], last[1000010];
bool b[1000010];
vector<int> vec[233333];
vector<pair<int, int> > query[233333];
void init() {
  for (int i = 2; i <= 1000000; ++i)
    if (b[i] == 0) {
      prime[++pid] = i;
      for (int j = i + i; j <= 1000000; j += i) b[j] = 1;
    }
  inv[1] = 1;
  for (int i = 2; i <= 1000000; ++i)
    inv[i] = ((1000000007 - 1000000007 / i) * inv[1000000007 % i]) % 1000000007;
}
void pushdown(int i) {
  if (mul[i] != 1) {
    mul[i << 1] = mul[i << 1] * mul[i] % 1000000007;
    mul[(i << 1) | 1] = mul[(i << 1) | 1] * mul[i] % 1000000007;
    mul[i] = 1;
  }
}
void update(int i, int l, int r, int a, int b, int x) {
  if (l == a && r == b)
    mul[i] = mul[i] * x % 1000000007;
  else {
    pushdown(i);
    int mid = (l + r) >> 1;
    if (b <= mid)
      update(i << 1, l, mid, a, b, x);
    else if (a > mid)
      update((i << 1) | 1, mid + 1, r, a, b, x);
    else {
      update(i << 1, l, mid, a, mid, x);
      update((i << 1) | 1, mid + 1, r, mid + 1, b, x);
    }
  }
}
long long Query(int i, int l, int r, int x) {
  if (l == r) return mul[i];
  pushdown(i);
  int mid = (l + r) >> 1;
  if (x <= mid) return Query(i << 1, l, mid, x);
  return Query((i << 1) | 1, mid + 1, r, x);
}
int main() {
  init();
  int q, x, y;
  scanf("%d", &n);
  f[0] = g[0] = 1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    int tmp = a[i];
    for (int j = 1; prime[j] * prime[j] <= tmp; ++j)
      if (tmp % prime[j] == 0) {
        vec[i].push_back(prime[j]);
        while (tmp % prime[j] == 0) tmp /= prime[j];
      }
    if (tmp != 1 && b[tmp] == 0) vec[i].push_back(tmp);
    f[i] = f[i - 1] * a[i] % 1000000007;
    g[i] = g[i - 1] * inv[a[i]] % 1000000007;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &x, &y);
    query[y].push_back(make_pair(x, i));
  }
  fill(mul + 1, mul + n * 4 + 1, 1);
  for (int i = 1; i <= n; ++i) {
    for (vector<int>::iterator j = vec[i].begin(); j != vec[i].end(); ++j) {
      update(1, 1, n, last[*j] + 1, i, (*j - 1) * inv[*j] % 1000000007);
      last[*j] = i;
    }
    for (vector<pair<int, int> >::iterator j = query[i].begin();
         j != query[i].end(); ++j)
      ans[j->second] = Query(1, 1, n, j->first) * f[i] % 1000000007 *
                       g[j->first - 1] % 1000000007;
  }
  for (int i = 1; i <= q; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
