#include <bits/stdc++.h>   using namespace std;   const int N = 2E5 + 10, mod = 1E9 + 7, M = 1E6 + 10, lim = 1E6;   int n, m, a[N], s[N], ans[N];   struct node {     int l, r, num;   } p[N];   vector<int> f[M];   int pos[M];   inline int cmp(node x, node y) { return x.r < y.r; }   struct sgtree {     int l, r, sum;   } t[N << 2];   inline int ksm(int x, int y) {     return y == 1                ? x                : 1ll * ksm(1ll * x * x % mod, y >> 1) * ((y & 1) ? x : 1) % mod;   }   inline void pl(int l = 1, int r = n, int x = 1) {     t[x] = (sgtree){l, r, 1};     if (l == r) return;     int mid = l + r >> 1;     pl(l, mid, x << 1);     pl(mid + 1, r, x << 1 | 1);   }   inline void modify(int l, int r, int v, int x = 1) {     if (l == t[x].l && r == t[x].r) {       t[x].sum = 1ll * t[x].sum * v % mod;       return;     }     int mid = t[x].l + t[x].r >> 1;     if (r <= mid)       modify(l, r, v, x << 1);     else if (l > mid)       modify(l, r, v, x << 1 | 1);     else       modify(l, mid, v, x << 1), modify(mid + 1, r, v, x << 1 | 1);   }   inline void insert(int v, int x) {     for (int i = 0; i < f[v].size(); i++) {       modify(pos[f[v][i]] + 1, x,              1ll * ksm(f[v][i], mod - 2) * (f[v][i] - 1) % mod);       pos[f[v][i]] = x;     }   }   inline int query(int l, int x = 1) {     if (t[x].l == t[x].r) return t[x].sum;     int mid = t[x].l + t[x].r >> 1;     return 1ll * t[x].sum * (l <= mid ? query(l, x << 1) : query(l, x << 1 | 1)) %            mod;   }   inline int sol(int l, int r) {     return 1ll * s[r] * ksm(s[l - 1], mod - 2) % mod * query(l) % mod;   }   int main() {     scanf( %d , &n);     s[0] = 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = 1ll * s[i - 1] * a[i] % mod;     }     scanf( %d , &m);     pl();     for (int i = 1; i <= m; i++) {       scanf( %d%d , &p[i].l, &p[i].r);       p[i].num = i;     }     sort(p + 1, p + 1 + m, cmp);     int now = 1;     for (int i = 2; i <= lim; i++)       if (!f[i].size())         for (int j = 1; i * j <= lim; j++) f[i * j].push_back(i);     for (int i = 1; i <= n; i++) {       insert(a[i], i);       while (now <= m && p[now].r == i) {         ans[p[now].num] = sol(p[now].l, p[now].r);         now++;       }     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }   