#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const int MOD = 1000000007;
void print(int x) {
  cout << x << endl;
  exit(0);
}
void PRINT(string x) {
  cout << x << endl;
  exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
vector<int> fj[N];
int a[N], vis[N], last[N], ans[N];
long long bit[N], pre[N];
int n, m;
struct node {
  int l, r, id;
} b[N];
bool cmp(node a, node b) { return a.r < b.r; }
long long pw(int a, int b) {
  long long res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % MOD)
    if (b & 1) res = res * a % MOD;
  return res;
}
long long inv(int x) { return pw(x, MOD - 2); }
void init(int n) {
  memset(vis, 0, sizeof(vis));
  for (int i = 2; i <= n; i++)
    if (!vis[i]) {
      for (int j = i; j <= n; j += i) {
        vis[j] = 1;
        fj[j].push_back(i);
      }
    }
}
void modify(int x, int val) {
  for (; x <= n; x += (x & -x)) bit[x] = bit[x] * val % MOD;
}
long long query(int x) {
  long long ans = 1;
  for (; x; x -= (x & -x)) ans = ans * bit[x] % MOD;
  return ans;
}
signed main() {
  init(1000000);
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = (1); i <= (m); i++) {
    scanf("%d%d", &b[i].l, &b[i].r);
    b[i].id = i;
  }
  sort(b + 1, b + m + 1, cmp);
  pre[0] = 1;
  int now = 1;
  memset(last, 0, sizeof(last));
  for (int i = (1); i <= (n); i++) bit[i] = 1;
  for (int i = (1); i <= (n); i++) {
    pre[i] = pre[i - 1] * a[i] % MOD;
    for (int j = (0); j <= (((int)fj[a[i]].size()) - 1); j++) {
      int tmp = fj[a[i]][j];
      if (last[tmp]) {
        modify(last[tmp], tmp);
        modify(last[tmp], inv(tmp - 1));
      }
      modify(i, tmp - 1);
      modify(i, inv(tmp));
      last[tmp] = i;
    }
    while (now <= m && b[now].r == i) {
      ans[b[now].id] = query(b[now].r) * inv(query(b[now].l - 1)) % MOD *
                       pre[b[now].r] % MOD * inv(pre[b[now].l - 1]) % MOD;
      now++;
    }
  }
  for (int i = (1); i <= (m); i++) printf("%d\n", ans[i]);
  return 0;
}
