#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[300000];
vector<pair<int, int> > ed[300000];
int tru[10000000], trd[10000000];
int trs[2000000];
int na[5000000], tout[300000], nxt[2000000], v, q, st[300000], en[300000],
    b[20000], mar[1000100];
const int base = 1e9 + 7;
int ans, k1;
void builds(int x, int l, int r) {
  if (l == r) {
    trs[x] = a[l];
    return;
  }
  int mid = (r + l) / 2;
  builds(x * 2, l, mid);
  builds(x * 2 + 1, mid + 1, r);
  trs[x] = (1ll * trs[x * 2] * trs[x * 2 + 1]) % base;
}
void buildt(int x, int l, int r) {
  if (l == r) {
    tru[x] = 1;
    trd[x] = 1;
    if (na[l] == 1) return;
    if (mar[na[l]] == l) {
      tru[x] = na[l] - 1;
      trd[x] = na[l];
    }
    return;
  }
  int mid = (r + l) / 2;
  buildt(x * 2, l, mid);
  buildt(x * 2 + 1, mid + 1, r);
  tru[x] = (1ll * tru[x * 2] * tru[x * 2 + 1]) % base;
  trd[x] = (1ll * trd[x * 2] * trd[x * 2 + 1]) % base;
}
void fnds(int x, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    ans = (1ll * ans * trs[x]) % base;
    return;
  }
  int mid = (r + l) / 2;
  if (ll <= mid) fnds(x * 2, l, mid, ll, rr);
  if (rr > mid) fnds(x * 2 + 1, mid + 1, r, ll, rr);
}
void fndt(int x, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    ans = (1ll * ans * tru[x]) % base;
    k1 = (1ll * k1 * trd[x]) % base;
    return;
  }
  int mid = (r + l) / 2;
  if (ll <= mid) fndt(x * 2, l, mid, ll, rr);
  if (rr > mid) fndt(x * 2 + 1, mid + 1, r, ll, rr);
}
void upd(int x, int l, int r, int ll, int u, int d) {
  if (d == 1) return;
  if (l == r) {
    tru[x] = (1ll * tru[x] * u) % base;
    trd[x] = (1ll * trd[x] * d) % base;
    return;
  }
  int mid = (r + l) / 2;
  if (ll <= mid) upd(x * 2, l, mid, ll, u, d);
  if (ll > mid) upd(x * 2 + 1, mid + 1, r, ll, u, d);
  tru[x] = (1ll * tru[x * 2] * tru[x * 2 + 1]) % base;
  trd[x] = (1ll * trd[x * 2] * trd[x * 2 + 1]) % base;
}
int mypw(int x, int y) {
  if (y == 1)
    return x;
  else if (y % 2 == 1) {
    int g = mypw(x, y - 1);
    return (1ll * g * x) % base;
  } else {
    int g = mypw(x, y / 2);
    return (1ll * g * g) % base;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 2; i <= 1000; i++) {
    if (mar[i] == 1) continue;
    v++;
    b[v] = i;
    int j = i;
    while (j <= 1000) {
      mar[j] = 1;
      j += i;
    }
  }
  for (int i = 1; i <= n; i++) {
    int x = a[i];
    st[i] = q + 1;
    if (x == 1) {
      q++;
      na[q] = 1;
    }
    for (int j = 1; j <= v; j++) {
      if (x % b[j] == 0) {
        q++;
        na[q] = b[j];
      }
      while (x % b[j] == 0) x = x / b[j];
    }
    if (x != 1) {
      q++;
      na[q] = x;
    }
    en[i] = q;
  }
  builds(1, 1, n);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    ed[l].push_back(make_pair(r, i));
  }
  for (int i = 1; i <= 1000; i++) mar[i] = 0;
  for (int i = q; i >= 1; i--) {
    nxt[i] = mar[na[i]];
    mar[na[i]] = i;
  }
  buildt(1, 1, q);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < ed[i].size(); j++) {
      int r = ed[i][j].first;
      int x = ed[i][j].second;
      ans = 1;
      k1 = 1;
      fnds(1, 1, n, i, r);
      fndt(1, 1, q, st[i], en[r]);
      ans = (1ll * ans * mypw(k1, base - 2)) % base;
      tout[x] = ans;
    }
    for (int j = st[i]; j <= en[i]; j++) {
      if (nxt[j] != 0) upd(1, 1, q, nxt[j], na[j] - 1, na[j]);
      upd(1, 1, q, j, na[j], na[j] - 1);
    }
  }
  for (int i = 1; i <= m; i++) cout << tout[i] << "\n";
  return 0;
}
