#include <bits/stdc++.h>   using namespace std;   const long long maxN = 2e5 + 10;   const long long maxB = 500;   const long long INF = 4557430888798830399;   const int INF_I = 2139062143;   const long long maxA = 1e6 + 10;   const long long MOD = 1e9 + 7;   const long long mINF = -4557430888798830400;   const int mINF_I = -2139062144;   template <typename T>   T binaryExpo(T n, T p) {     if (p == 0) {       return 1LL;     }     if (p & 1) {       return n * binaryExpo(n, p - 1);     }     T ret = binaryExpo(n, p / 2);     return ret * ret;   }   template <typename T>   T bigMod(T n, T p, T m) {     if (p == 0) {       return 1LL % m;     }     if (p & 1) {       return (n % m * bigMod(n, p - 1, m)) % m;     }     T ret = bigMod(n, p / 2, m) % m;     return (ret * ret) % m;   }   template <typename T>   T modInv(T n, T m) {     return bigMod(n, m - 2, m);   }   bool FILE_PRINT = 0;   int marked[+2];   vector<long long> prime;   void sieve(long long n);   bool is_prime(long long num);   int arr[maxN + 10], ans[maxN + 10], idx[maxN + 10];   long long cum[maxN + 10];   pair<int, int> query[maxN + 10];   vector<int> divisors[maxN + 10];   long long spd[maxA + 10];   long long mp[maxN + 10];   void calc_spd(long long n) {     memset(spd, -1, sizeof spd);     for (long long i = 2; i <= n; i++) {       if (spd[i] == -1) {         prime.push_back(i);         mp[prime.size() - 1] = ((i - 1) * modInv(i, MOD)) % MOD;         for (long long j = i; j <= n; j += i) {           if (spd[j] == -1) spd[j] = prime.size() - 1;         }       }     }   }   inline bool compare(long long x, long long y) {     return make_pair(query[x].first / maxB, query[x].second) <            make_pair(query[y].first / maxB, query[y].second);   }   signed cnt[maxN + 10];   void solve(long long n, long long q) {     long long a, b = -1, l, r, ans = 1;     for (long long curr_block = -1, i = 0; i < q; i++) {       tie(l, r) = query[idx[i]];       if (l / maxB != curr_block) {         curr_block = l / maxB;         ans = 1;         memset(cnt, 0, sizeof cnt);         b = (curr_block + 1) * maxB - 1;       }       while (b + 1 <= r) {         b++;         for (auto p : divisors[b]) {           if (cnt[p] == 0) ans = (ans * mp[p]) % MOD;           cnt[p]++;         }       }       long long temp = ans;       for (a = l; a <= min(r, (curr_block + 1) * maxB - 1); a++) {         for (auto p : divisors[a]) {           if (cnt[p] == 0) ans = (ans * mp[p]) % MOD;           cnt[p]++;         }       }       if (ans < 0) ans += MOD;       ::ans[idx[i]] = (::ans[idx[i]] * ans) % MOD;       for (a = l; a <= min(r, (curr_block + 1) * maxB - 1); a++) {         for (auto p : divisors[a]) {           cnt[p]--;         }       }       ans = temp;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(15);     cout << fixed;     calc_spd(maxA + 5);     long long number_of_test_cases = 1, test_case;     for (test_case = 1; test_case <= number_of_test_cases; test_case++) {       long long i, j, k, l, r, m, n, query_type, q;       long long a, b, c, x, y, z;       cin >> n;       for (i = (0); i < (n); ++i) {         cin >> arr[i];         x = arr[i];         while (x > 1) {           long long p = spd[x];           while (x % prime[p] == 0) {             x /= prime[p];           }           divisors[i].push_back(p);         }       }       cum[0] = arr[0];       for (i = (1); i <= (n - 1); ++i) {         cum[i] = (cum[i - 1] * arr[i]) % MOD;       }       cin >> q;       for (i = (0); i < (q); ++i) {         cin >> l >> r;         l--;         r--;         query[i] = make_pair(l, r);         ans[i] = cum[r];         if (l > 0) ans[i] = (ans[i] * modInv((long long)cum[l - 1], MOD)) % MOD;       }       for (i = (0); i < (q); ++i) idx[i] = i;       sort(idx, idx + q, compare);       solve(n, q);       for (i = (0); i < (q); ++i) cout << ans[i] <<   n ;     }     return 0;   }   bool is_prime(long long num) {     return (num > 1 &&             (num == 2 || ((((num)&1LL) ? (1) : (0)) &&                           !(marked[(num) >> 6] & (1L << (((num) % 64) >> 1))))));   }   void sieve(long long n) {     long long i, j;     (marked[(1) >> 6] |= (1L << (((1) % 64) >> 1)));     for (i = 3; i * i <= n; i += 2) {       if (!(marked[(i) >> 6] & (1L << (((i) % 64) >> 1)))) {         for (j = i * i; j <= n; j += i + i)           (marked[(j) >> 6] |= (1L << (((j) % 64) >> 1)));       }     }     prime.clear();     prime.push_back(2);     for (i = 3; i <= n; i += 2) {       if (is_prime(i)) prime.push_back(i);     }   }