#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010, MAXV = 1000010, mod = 1000000007;
inline int add(int a, int b) { return (a + b) % mod; }
inline int mul(int a, int b) { return ((long long int)a * b) % mod; }
inline int potenciraj(int a, int x) {
  int ret = 1;
  while (x) {
    if (x & 1) ret = mul(ret, a);
    a = mul(a, a);
    x /= 2;
  }
  return ret;
}
inline int dijeli(int a, int b) { return mul(a, potenciraj(b, mod - 2)); }
struct query {
  int a, b, redni;
  query(int _a = 0, int _b = 0, int _redni = 0) {
    a = _a;
    b = _b;
    redni = _redni;
  }
};
int n;
int niz[MAXN], umnozak[MAXN], rj[MAXN];
int faktor[MAXV], naprijed[MAXV], nazad[MAXV], imam[MAXV];
int FWT[MAXV];
vector<int> pos[MAXV];
int it[MAXV];
vector<int> moji_faktori[MAXN];
vector<query> event[MAXN];
void postavi() {
  umnozak[0] = 1;
  for (int i = 0; i < MAXV; i++) faktor[i] = 1;
  for (int i = 2; i < MAXV; i++)
    if (faktor[i] == 1)
      for (int j = i; j < MAXV; j += i) faktor[j] = i;
  for (int i = 2; i < MAXV; i++)
    if (faktor[i] == i) {
      naprijed[i] = dijeli(i - 1, i);
      nazad[i] = dijeli(i, i - 1);
    }
  for (int i = 0; i < MAXV; i++) FWT[i] = 1;
}
void slozi_moje_faktore() {
  for (int br = 1; br <= n; br++) {
    int x = niz[br];
    while (x != 1) {
      int sad = faktor[x];
      if (!imam[sad]) {
        imam[sad] = 1;
        moji_faktori[br].push_back(sad);
      }
      x = x / faktor[x];
    }
    for (int i = 0; i < moji_faktori[br].size(); i++)
      imam[moji_faktori[br][i]] = 0;
    for (int i = 0; i < moji_faktori[br].size(); i++) {
      int sad = moji_faktori[br][i];
      pos[sad].push_back(br);
    }
  }
}
void ubaci(int x, int v) {
  for (; x < MAXV; x += x & -x) FWT[x] = mul(FWT[x], v);
}
int upit(int x) {
  int ret = 1;
  for (; x > 0; x -= x & -x) ret = mul(ret, FWT[x]);
  return ret;
}
int main() {
  postavi();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &niz[i]);
    umnozak[i] = mul(umnozak[i - 1], niz[i]);
  }
  slozi_moje_faktore();
  int q;
  scanf("%d", &q);
  for (int br = 0; br < q; br++) {
    int a, b;
    scanf("%d %d", &a, &b);
    event[a].push_back(query(a, b, br));
  }
  for (int i = 0; i < MAXV; i++)
    if (it[i] < pos[i].size()) ubaci(pos[i][it[i]], naprijed[i]);
  for (int i = 1; i <= n; i++) {
    for (int br = 0; br < event[i].size(); br++) {
      int a = event[i][br].a;
      int b = event[i][br].b;
      int redni = event[i][br].redni;
      int glavni = dijeli(umnozak[b], umnozak[a - 1]);
      int sporedni = upit(b);
      rj[redni] = mul(glavni, sporedni);
    }
    for (int br = 0; br < moji_faktori[i].size(); br++) {
      int sad = moji_faktori[i][br];
      if (it[sad] < pos[sad].size()) {
        ubaci(pos[sad][it[sad]], nazad[sad]);
        it[sad]++;
      }
      if (it[sad] < pos[sad].size()) ubaci(pos[sad][it[sad]], naprijed[sad]);
    }
  }
  for (int i = 0; i < q; i++) printf("%d\n", rj[i]);
  return 0;
}
