#include <bits/stdc++.h>
using namespace std;
int n, q, x, y;
int ans[200005], S[200005 * 4], p[1000000 + 5], val[1000000 + 5], a[200005],
    pre[200005];
vector<int> prs[1000000 + 5], now[1000000 + 5];
vector<pair<pair<int, int>, int> > qu;
int fe(int x, int y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  int res = fe(x, y / 2);
  res = 1ll * res * res % 1000000007;
  if (y & 1) res = 1ll * res * x % 1000000007;
  return res;
}
int get(int node, int bas, int son, int x, int y) {
  if (bas > y || son < x) return 1;
  if (bas >= x && son <= y) return S[node];
  return 1ll * get(node * 2, bas, ((bas + son) / 2), x, y) *
         get(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y) % 1000000007;
}
void up(int node, int bas, int son, int x, int deg, int w) {
  if (bas > x || son < x) return;
  if (bas == x && son == x) {
    if (w) {
      S[node] = 1ll * S[node] * val[deg] % 1000000007;
    } else {
      S[node] = 1ll * S[node] * fe(val[deg], 1000000007 - 2) % 1000000007;
    }
    return;
  }
  up(node * 2, bas, ((bas + son) / 2), x, deg, w);
  up(node * 2 + 1, ((bas + son) / 2) + 1, son, x, deg, w);
  S[node] = 1ll * S[node * 2] * S[node * 2 + 1] % 1000000007;
}
void sieve() {
  for (int i = 2; i <= 1000000; i++) {
    if (!p[i]) {
      for (int j = i; j <= 1000000; j += i) {
        p[j] = 1;
        prs[j].push_back(i);
      }
      val[i] = (1 - fe(i, 1000000007 - 2) + 1000000007) % 1000000007;
    }
  }
}
int main() {
  for (int i = 0; i < 200005 * 4; i++) S[i] = 1;
  sieve();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)prs[a[i]].size(); j++) {
      now[prs[a[i]][j]].push_back(i);
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    qu.push_back({{x, y}, i});
  }
  sort(qu.begin(), qu.end());
  for (int i = 2; i <= 1000000; i++) {
    reverse(now[i].begin(), now[i].end());
    if ((int)now[i].size()) {
      up(1, 1, n, now[i].back(), i, 1);
    }
  }
  pre[0] = 1;
  for (int i = 1; i <= n; i++) {
    pre[i] = 1ll * pre[i - 1] * a[i] % 1000000007;
  }
  int last = 1;
  for (int i = 0; i < q; i++) {
    while (last < qu[i].first.first) {
      for (int j = 0; j < (int)prs[a[last]].size(); j++) {
        if ((int)now[prs[a[last]][j]].size()) {
          up(1, 1, n, now[prs[a[last]][j]].back(), prs[a[last]][j], 0);
          now[prs[a[last]][j]].pop_back();
          if ((int)now[prs[a[last]][j]].size()) {
            up(1, 1, n, now[prs[a[last]][j]].back(), prs[a[last]][j], 1);
          }
        }
      }
      last++;
    }
    ans[qu[i].second] =
        1ll * get(1, 1, n, qu[i].first.first, qu[i].first.second) *
        pre[qu[i].first.second] % 1000000007 *
        fe(pre[qu[i].first.first - 1], 1000000007 - 2) % 1000000007;
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
}
