#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void gn(T &x) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), x = 0; c >= '0' && c <= '9';
       c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  if (sg) x = -x;
}
template <class T, class T1>
inline void gn(T &x, T1 &y) {
  gn(x);
  gn(y);
}
template <class T, class T1, class T2>
inline void gn(T &x, T1 &y, T2 &z) {
  gn(x);
  gn(y);
  gn(z);
}
template <class T>
inline void print(T x) {
  if (x < 0) {
    putchar('-');
    return print(-x);
  }
  if (x < 10) {
    putchar('0' + x);
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void printsp(T x) {
  print(x);
  putchar(' ');
}
template <class T>
inline void println(T x) {
  print(x);
  putchar('\n');
}
template <class T, class U>
inline void print(T x, U y) {
  printsp(x);
  println(y);
}
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int a[200010], len[200010], cnt[1000010];
pair<pair<int, int>, int> pp[200010];
int res[200010], s[200010], t[200010], ff[1000010], fg[1000010], gf[1000010],
    p[200010][11], H[1000010], prime[200010], np;
int cur = 1;
int N;
void prepare() {
  for (int i = 1; i < 1000010; i++)
    H[i] = i < 2 ? i
                 : (long long)1000000007 / i *
                       (1000000007 - H[1000000007 % i]) % 1000000007;
  for (int i = 2; i < 1000010; i++) {
    if (!ff[i]) {
      fg[i] = (long long)(i - 1) * H[i] % 1000000007;
      gf[i] = (long long)i * H[i - 1] % 1000000007;
      prime[np++] = i;
      ff[i] = i;
    }
    for (int j = 0; j < np && prime[j] * i < 1000010; j++) {
      ff[i * prime[j]] = prime[j];
      if (ff[i] == prime[j]) break;
    }
  }
}
int I[200010];
inline bool cmp(int u, int v) {
  if (pp[u].first.first / N == pp[v].first.first / N)
    return pp[u].first.second < pp[v].first.second;
  return pp[u].first.first < pp[v].first.first;
}
void f(int u, int h) {
  if (h == 1) {
    for (int i = 1; i <= len[u]; i++) {
      if (cnt[p[u][i]] == 0) {
        cur = (long long)cur * fg[p[u][i]] % 1000000007;
      }
      cnt[p[u][i]]++;
    }
  }
  if (h == -1) {
    for (int i = 1; i <= len[u]; i++) {
      cnt[p[u][i]]--;
      if (cnt[p[u][i]] == 0) {
        cur = (long long)gf[p[u][i]] * cur % 1000000007;
      }
    }
  }
}
int main() {
  prepare();
  int n;
  gn(n);
  s[0] = 1;
  t[0] = 1;
  for (int i = 1; i <= n; i++) {
    gn(a[i]);
    s[i] = (long long)s[i - 1] * a[i] % 1000000007;
    int yy = a[i];
    while (yy > 1) {
      int g = ff[yy];
      p[i][++len[i]] = g;
      while (yy % g == 0) yy /= g;
    }
  }
  t[n] = power(s[n], 1000000007 - 2, 1000000007);
  for (int i = n - 1; i >= 1; i--) {
    t[i] = (long long)t[i + 1] * a[i + 1] % 1000000007;
  }
  N = (int)sqrt(n) + 1;
  int q;
  gn(q);
  for (int i = 1; i <= q; i++) {
    gn(pp[i].first.first, pp[i].first.second);
    pp[i].second = i;
    I[i] = i;
  }
  sort(I + 1, I + 1 + q, cmp);
  int st = 1, ed = 0;
  for (int j = 1; j <= q; j++) {
    int i = I[j];
    int l = pp[i].first.first, r = pp[i].first.second;
    int id = pp[i].second;
    while (ed < r) f(++ed, 1);
    while (st > l) f(--st, 1);
    while (ed > r) f(ed--, -1);
    while (st < l) f(st++, -1);
    int ans = (long long)s[r] * t[l - 1] % 1000000007;
    ans = (long long)ans * cur % 1000000007;
    res[id] = ans;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", res[i]);
  return 0;
}
