#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int seg[maxn << 2];
int a[maxn];
int n;
bool visited[1000002];
vector<int> primelist;
vector<int> primepos[81800];
int currentPos[81800];
vector<int> factors[1000002];
int ans[maxn];
int primenum;
const int MOD = 1000000007;
void sieve() {
  memset(visited, 0, sizeof(visited));
  for (int i = 2; i < 1e6; i++) {
    if (visited[i] == false) {
      primelist.push_back(i);
      int od = primelist.size() - 1;
      factors[i].push_back(od);
      for (int j = 2 * i; j < 1e6; j += i) {
        visited[j] = true;
        factors[j].push_back(od);
      }
    }
  }
}
int mul(int a, int b) {
  int c = (long long)a * (long long)b % MOD;
  return c;
}
int fastpower(int a, int k) {
  int res = 1;
  int temp = a;
  while (k) {
    if (k & 1) res = mul(res, temp);
    temp = mul(temp, temp);
    k /= 2;
  }
  return res;
}
int inv(int a) { return fastpower(a, MOD - 2); }
void PushUP(int rt) { seg[rt] = mul(seg[rt << 1], seg[rt << 1 | 1]); }
struct qu {
  int index;
  int left;
  int right;
  qu(int i = 0, int l = 0, int r = 0) {
    index = i;
    left = l;
    right = r;
  }
};
qu querries[maxn];
bool cmp(qu a, qu b) {
  if (a.left == b.left)
    return a.right < b.right;
  else
    return a.left < b.left;
}
void build(int l, int r, int rt) {
  seg[rt] = a[l];
  if (l == r) {
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  PushUP(rt);
}
void update(int p, int c, int l, int r, int rt) {
  if (l == r) {
    seg[rt] = mul(seg[rt], c);
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    update(p, c, l, m, rt << 1);
  else
    update(p, c, m + 1, r, rt << 1 | 1);
  PushUP(rt);
}
int query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return seg[rt];
  }
  int ret = 1;
  ;
  int m = (l + r) >> 1;
  if (L <= m) ret = mul(ret, query(L, R, l, m, rt << 1));
  if (R > m) ret = mul(ret, query(L, R, m + 1, r, rt << 1 | 1));
  return ret;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  sieve();
  cin >> n;
  primenum = primelist.size();
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    a[i] = t;
    for (int j = 0; j < factors[t].size(); j++) {
      primepos[factors[t][j]].push_back(i);
    }
  }
  build(1, n, 1);
  for (int i = 0; i < primenum; i++) {
    if (primepos[i].size() > 0) {
      int p = primelist[i];
      int pos = primepos[i][0];
      update(pos, mul(p - 1, inv(p)), 1, n, 1);
      currentPos[i] = 0;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    querries[i] = qu(i, l, r);
  }
  sort(querries, querries + q, cmp);
  int leftmost = 1;
  for (int i = 0; i < q; i++) {
    int l = querries[i].left;
    while (leftmost < l) {
      for (int j = 0; j < factors[a[leftmost]].size(); j++) {
        currentPos[factors[a[leftmost]][j]]++;
        if (currentPos[factors[a[leftmost]][j]] <
            primepos[factors[a[leftmost]][j]].size()) {
          int p = primelist[factors[a[leftmost]][j]];
          update(primepos[factors[a[leftmost]][j]]
                         [currentPos[factors[a[leftmost]][j]]],
                 mul(p - 1, inv(p)), 1, n, 1);
        }
      }
      leftmost++;
    }
    ans[querries[i].index] = query(l, querries[i].right, 1, n, 1);
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
