#include <bits/stdc++.h>
int primes[168];
void init() {
  static char composite[1000 + 1];
  int a, b, k;
  for (a = 2; a <= 1000 / a; a++) {
    if (composite[a]) continue;
    for (b = a * a; b <= 1000; b += a) composite[b] = 1;
  }
  k = 0;
  for (a = 2; a <= 1000; a++)
    if (!composite[a]) primes[k++] = a;
}
int d_, x_, y_;
void gcd_(int a, int b) {
  if (b == 0)
    d_ = a, x_ = 1, y_ = 0;
  else {
    int tmp;
    gcd_(b, a % b);
    tmp = x_ - a / b * y_, x_ = y_, y_ = tmp;
  }
}
int inv(int a) {
  gcd_(a, 1000000007);
  if (x_ < 0) x_ += 1000000007;
  return x_;
}
int ll[200000], rr[200000];
int compare(const void *a, const void *b) {
  int h1 = *(int *)a;
  int h2 = *(int *)b;
  return ll[h2] - ll[h1];
}
int ft[200000];
void update(int i, int n, int x) {
  while (i < n) {
    ft[i] = (long long)ft[i] * x % 1000000007;
    i |= i + 1;
  }
}
int query(int i) {
  int x = 1;
  while (i >= 0) {
    x = (long long)x * ft[i] % 1000000007;
    i &= i + 1, i--;
  }
  return x;
}
int main() {
  static int aa[200000], pp[200000], hh[200000], ans[200000], next[1000000 + 1];
  int n, q, g, h, i, a, l;
  init();
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &aa[i]);
    pp[i] = (long long)(i == 0 ? 1 : pp[i - 1]) * aa[i] % 1000000007;
  }
  scanf("%d", &q);
  for (h = 0; h < q; h++) {
    scanf("%d%d", &ll[h], &rr[h]), ll[h]--, rr[h]--;
    ans[h] = (long long)pp[rr[h]] * (ll[h] == 0 ? 1 : inv(pp[ll[h] - 1])) %
             1000000007;
  }
  for (h = 0; h < q; h++) hh[h] = h;
  qsort(hh, q, sizeof *hh, compare);
  for (a = 2; a <= 1000000; a++) next[a] = n;
  for (i = 0; i < n; i++) ft[i] = 1;
  for (h = 0, l = n - 1; h < q; h++) {
    int h_ = hh[h];
    while (l >= ll[h_]) {
      int a = aa[l], p, x;
      for (g = 0; g < 168; g++) {
        p = primes[g];
        if (a % p == 0) {
          x = (long long)(p - 1) * inv(p) % 1000000007;
          update(next[p], n, inv(x));
          update(l, n, x);
          while (a % p == 0) a /= p;
          next[p] = l;
        }
      }
      if (a > 1) {
        p = a;
        x = (long long)(p - 1) * inv(p) % 1000000007;
        update(next[p], n, inv(x));
        update(l, n, x);
        while (a % p == 0) a /= p;
        next[p] = l;
      }
      aa[i] = a;
      l--;
    }
    ans[h_] = (long long)ans[h_] * query(rr[h_]) % 1000000007;
  }
  for (h = 0; h < q; h++) printf("%d\n", ans[h]);
  return 0;
}
