#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T &v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct Z {
  int l;
  int r;
  int i;
};
template <class T>
class SegmentTree {
  int maxn = 1000000;
  vector<T> t;
  void build(const vector<int> &a, int v, int tl, int tr) {
    if (tl == tr) {
      t[v] = a[tl];
    } else {
      int tm = (tl + tr) / 2;
      build(a, v * 2 + 1, tl, tm);
      build(a, v * 2 + 2, tm + 1, tr);
      t[v] = (t[v * 2 + 1] * t[v * 2 + 2]) % MOD;
    }
  }
  T sum(int v, int tl, int tr, int l, int r) {
    if (l > r) {
      return 1;
    }
    if (l == tl && r == tr) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    return (sum(v * 2 + 1, tl, tm, l, min(r, tm)) *
            sum(v * 2 + 2, tm + 1, tr, max(l, tm + 1), r)) %
           MOD;
  }
  void update(int v, int tl, int tr, int pos, T new_val) {
    if (tl == tr) {
      t[v] += new_val;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        update(v * 2 + 1, tl, tm, pos, new_val);
      } else {
        update(v * 2 + 2, tm + 1, tr, pos, new_val);
      }
      t[v] = (t[v * 2 + 1] * t[v * 2 + 2]) % MOD;
    }
  }

 public:
  SegmentTree(int n) {
    maxn = n;
    t.resize(4 * maxn);
  }
  SegmentTree(const vector<int> &a) {
    maxn = a.size();
    t.resize(4 * maxn);
    build(a, 0, 0, maxn - 1);
  }
  void update(int pos, T add) { update(0, 0, maxn - 1, pos, add); }
  T sum(int l, int r) { return sum(0, 0, maxn - 1, l, r); }
};
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int __i = 0; __i < (n); ++__i) cin >> v[__i];
  ;
  int C = 1000001;
  vector<int> lp(C + 1);
  vector<int> pr;
  for (int i = (2); i < (C + 1); ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= C;
         ++j) {
      lp[i * pr[j]] = pr[j];
    }
  }
  vector<int> a;
  vector<int> pos(n);
  for (int i = (0); i < (n); ++i) {
    pos[i] = a.size();
    int t = v[i];
    while (t != 1) {
      a.push_back(lp[t]);
      t /= lp[t];
    }
  }
  pos.push_back(a.size());
  vector<vector<int>> s(C);
  for (int i = (0); i < (a.size()); ++i) {
    s[a[i]].push_back(i);
  }
  for (auto &i : s) {
    reverse(i.begin(), i.end());
    if (i.size()) {
      --a[i.back()];
    }
  }
  SegmentTree<long long> tr(a);
  for (auto &i : s) {
    if (i.size()) {
      ++a[i.back()];
    }
  }
  int m;
  cin >> m;
  vector<Z> q(m);
  for (int i = (0); i < (m); ++i) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    q[i] = {l, r, i};
  }
  sort(q.begin(), q.end(), [](const Z &a, const Z &b) { return a.l < b.l; });
  vector<int> ans(m);
  int j = 0;
  for (int i = (0); i < (m); ++i) {
    while (j < pos[q[i].l]) {
      s[a[j]].pop_back();
      if (a[j] != 1 && s[a[j]].size()) {
        tr.update(s[a[j]].back(), -1);
      }
      ++j;
    }
    ans[q[i].i] = tr.sum(pos[q[i].l], pos[q[i].r + 1] - 1);
  }
  for (auto i : ans) {
    cout << i << "\n";
  }
}
