#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
const int maxn= 2e5+10,maxm= 1e6+10,M= 1e6,mo= 1e9+7;
//const int maxn= 3e3,maxm= 1e3+10,M= 1e3,mo= 1e9+7;
struct query{
	int l,r,h;
}Q[maxn];
ll ans[maxn];
int inv[maxm],A[maxm][10],L[maxm],vis[maxm],sta[maxm];
int B[maxn][10],C[maxn];
int up[maxm],down[maxm],sum[maxn];
int a[maxn];
ll now;
int i,j,k,q,l,r,n,m,la,x,y,z,base;
bool cmpl(query a,query b){
	return a.l<b.l||(a.l==b.l&&a.r<b.r);
}
bool cmpr(query a,query b){
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
void gcd(int a,int b,int &x,int &y){
	if (!b){
		x= 1;
		y= 0;
		return;
	}
	gcd(b,a%b,x,y);
	int t= x;
	x= y;
	y= t-a/b*y;
}
void add(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]++;
		if (vis[y]==1)
			now= now*up[y]%mo;
	}
}
void del(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]--;
		if (vis[y]==0)
			now= now*down[y]%mo;
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	gcd(1,mo,inv[1],y);
	up[1]= down[1]= 1;
	for (i= 2;i<=M;i++){
		gcd(i,mo,inv[i],y);
		inv[i]= (inv[i]+mo)%mo;
		up[i]= (ll)(i-1)*inv[i]%mo;
		down[i]= (ll)i*inv[i-1]%mo;
		if (vis[i]) continue;
		sta[++la]= i;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	scanf("%d",&n);
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]= (ll)sum[i-1]*a[i]%mo;
		C[i]= L[a[i]];
		for (j= 1;j<=C[i];j++)
			B[i][j]= A[a[i]][j];
	}
	scanf("%d",&q);
	base= 600;
	for (i= 1;i<=q;i++){
		scanf("%d%d",&x, &y);
		Q[i]= (query){x,y,i};
	}
	sort(Q+1,Q+q+1,cmpl);
	memset(vis,0,sizeof(vis));
	l= r= 0;
	now= 1;
	for (i= 1;i<=q;i+= base){
		//for (j= 1;j<=la;j++) vis[sta[j]]= 0;
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		for (j= i;j<=m;j++){
			x= Q[j].l,y= Q[j].r;
			if (x<l)
				for (k= x;k<l;k++)
					add(k);
			else for (k= l;k<x;k++)
					 del(k);
			if (y<r)
				for (k= y+1;k<=r;k++)
					del(k);
			else for (k= r+1;k<=y;k++)
					 add(k);
			l= x;r= y;
			gcd(sum[l-1],mo,x,y);
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%lld\n",(ans[i]+mo)%mo);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
const int maxn= 3e5,maxm= 1e6+10,M= 1e6,mo= 1e9+7;
//const int maxn= 3e3,maxm= 1e3+10,M= 1e3,mo= 1e9+7;
struct query{
	int l,r,h;
}Q[maxn];
ll ans[maxn];
int inv[maxm],A[maxm][10],L[maxm],vis[maxm],sta[maxm];
int up[maxm],down[maxm],sum[maxn];
int a[maxn];
ll now;
int i,j,k,q,l,r,n,m,la,x,y,z,base;
bool cmpl(query a,query b){
	return a.l<b.l||(a.l==b.l&&a.r<b.r);
}
bool cmpr(query a,query b){
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
void gcd(int a,int b,int &x,int &y){
	if (!b){
		x= 1;
		y= 0;
		return;
	}
	gcd(b,a%b,x,y);
	int t= x;
	x= y;
	y= t-a/b*y;
}
void add(int x){
	for (int i= 1;i<=L[x];i++){
		int y= A[x][i];
		vis[y]++;
		if (vis[y]==1)
			now= now*up[y]%mo;
	}
}
void del(int x){
	for (int i= 1;i<=L[x];i++){
		int y= A[x][i];
		vis[y]--;
		if (vis[y]==0)
			now= now*down[y]%mo;
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	gcd(1,mo,inv[1],y);
	up[1]= down[1]= 1;
	for (i= 2;i<=M;i++){
		gcd(i,mo,inv[i],y);
		inv[i]= (inv[i]+mo)%mo;
		up[i]= (ll)(i-1)*inv[i]%mo;
		down[i]= (ll)i*inv[i-1]%mo;
		if (vis[i]) continue;
		sta[++la]= i;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	scanf("%d",&n);
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]= (ll)sum[i-1]*a[i]%mo;
	}
	scanf("%d",&q);
	base= 475;
	for (i= 1;i<=q;i++){
		scanf("%d%d",&x, &y);
		Q[i]= (query){x,y,i};
	}
	sort(Q+1,Q+q+1,cmpl);
	memset(vis,0,sizeof(vis));
	l= r= 0;
	now= 1;
	for (i= 1;i<=q;i+= base){
		//for (j= 1;j<=la;j++) vis[sta[j]]= 0;
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		for (j= i;j<=m;j++){
			x= Q[j].l,y= Q[j].r;
			if (x<l)
				for (k= x;k<l;k++)
					add(a[k]);
			else for (k= l;k<x;k++)
					 del(a[k]);
			if (y<r)
				for (k= y+1;k<=r;k++)
					del(a[k]);
			else for (k= r+1;k<=y;k++)
					 add(a[k]);
			l= x;r= y;
			gcd(sum[l-1],mo,x,y);
			ans[Q[j].h]= (now*sum[r]%mo*x%mo+mo)%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%lld\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
const int maxn= 2e5+10,maxm= 1e6+10,M= 1e6,mo= 1e9+7;
//const int maxn= 3e3,maxm= 1e3+10,M= 1e3,mo= 1e9+7;
struct query{
	int l,r,h;
}Q[maxn];
ll ans[maxn];
int A[maxm][10],L[maxm],vis[maxm];
int B[maxn][10],C[maxn];
int up[maxm],down[maxm],sum[maxn];
int a[maxn];
ll now;
int i,j,k,q,l,r,n,m,x,y,z,base,xx,yy,X,Y,I;
bool cmpl(query a,query b){
	return a.l<b.l||(a.l==b.l&&a.r<b.r);
}
bool cmpr(query a,query b){
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
void gcd(int a,int b,int &x,int &y){
	if (!b){
		x= 1;
		y= 0;
		return;
	}
	gcd(b,a%b,x,y);
	int t= x;
	x= y;
	y= t-a/b*y;
}
void add(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]++;
		if (vis[y]==1)
			now= now*up[y]%mo;
	}
}
void del(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]--;
		if (vis[y]==0)
			now= now*down[y]%mo;
	}
}
void read(int &x){
	char c= getchar();x= 0;
	while (c<'0'||c>'9') c= getchar();
	while ('0'<=c&&c<='9')x= x*10+c-'0',c= getchar();
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	scanf("%d",&n);
	up[1]= down[1]= 1;
	for (i= 2;i<=M;i++){
		if (vis[i]) continue;
		gcd(i,mo,x,y);
		gcd(i-1,mo,xx,yy);
		x= (x+mo)%mo;
		xx= (xx+mo)%mo;
		up[i]= (ll)(i-1)*x%mo;
		down[i]= (ll)i*xx%mo;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	//if (n>1e5) return 0;
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]= (ll)sum[i-1]*a[i]%mo;
		C[i]= L[a[i]];
		for (j= 1;j<=C[i];j++)
			B[i][j]= A[a[i]][j];
	}
	scanf("%d",&q);
	base= 600;
	for (i= 1;i<=q;i++){
		scanf("%d%d",&x, &y);
		Q[i]= (query){x,y,i};
	}
	sort(Q+1,Q+q+1,cmpl);
	memset(vis,0,sizeof(vis));
	l= r= 0;
	now= 1;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5+9e4) return 0;
		}
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		for (j= i;j<=m;j++){
			x= Q[j].l,y= Q[j].r;
			while (x<l){
				l--;
				//add(l);//
				for (I= 1;I<=C[l];I++){
					X= B[l][I];
					vis[X]++;
					if (vis[X]==1)
						now= now*up[X]%mo;
				}
			}
			while (l<x){
				//del(l);
				for (I= 1;I<=C[l];I++){
					X= B[l][I];
					vis[X]--;
					if (vis[X]==0)
						now= now*down[X]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (I= 1;I<=C[r];I++){
					X= B[r][I];
					vis[X]--;
					if (vis[X]==0)
						now= now*down[X]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);
				for (I= 1;I<=C[r];I++){
					X= B[r][I];
					vis[X]++;
					if (vis[X]==1)
						now= now*up[X]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%lld\n",(ans[i]+mo)%mo);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
const int maxn= 2e5+10,maxm= 1e6+10,M= 1e6,mo= 1e9+7;
//const int maxn= 3e3,maxm= 1e3+10,M= 1e3,mo= 1e9+7;
struct query{
	int l,r,h;
}Q[maxn];
ll ans[maxn];
int A[maxm][10],L[maxm],vis[maxm];
int B[maxn][10],C[maxn];
int up[maxm],down[maxm],sum[maxn];
int a[maxn];
ll now;
int i,j,k,q,l,r,n,m,x,y,z,base,xx,yy,X,Y,I;
bool cmpl(query a,query b){
	return a.l<b.l||(a.l==b.l&&a.r<b.r);
}
bool cmpr(query a,query b){
	return a.r<b.r||(a.r==b.r&&a.l<b.l);
}
void gcd(int a,int b,int &x,int &y){
	if (!b){
		x= 1;
		y= 0;
		return;
	}
	gcd(b,a%b,x,y);
	int t= x;
	x= y;
	y= t-a/b*y;
}
void add(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]++;
		if (vis[y]==1)
			now= now*up[y]%mo;
	}
}
void del(int x){
	for (int i= 1;i<=C[x];i++){
		int y= B[x][i];
		vis[y]--;
		if (vis[y]==0)
			now= now*down[y]%mo;
	}
}
void read(int &x){
	char c= getchar();x= 0;
	while (c<'0'||c>'9') c= getchar();
	while ('0'<=c&&c<='9')x= x*10+c-'0',c= getchar();
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	scanf("%d",&n);
	up[1]= down[1]= 1;
	for (i= 2;i<=M;i++){
		if (vis[i]) continue;
		gcd(i,mo,x,y);
		gcd(i-1,mo,xx,yy);
		x= (x+mo)%mo;
		xx= (xx+mo)%mo;
		up[i]= (ll)(i-1)*x%mo;
		down[i]= (ll)i*xx%mo;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	//if (n>1e5) return 0;
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]= (ll)sum[i-1]*a[i]%mo;
		C[i]= L[a[i]];
		for (j= 1;j<=C[i];j++)
			B[i][j]= A[a[i]][j];
	}
	scanf("%d",&q);
	base= 600;
	for (i= 1;i<=q;i++){
		scanf("%d%d",&x, &y);
		Q[i]= (query){x,y,i};
	}
	sort(Q+1,Q+q+1,cmpl);
	memset(vis,0,sizeof(vis));
	l= r= 0;
	now= 1;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5+9e4+1) return 0;
		}
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		for (j= i;j<=m;j++){
			x= Q[j].l,y= Q[j].r;
			while (x<l){
				l--;
				//add(l);//
				for (I= 1;I<=C[l];I++){
					Y= B[l][I];
					vis[Y]++;
					if (vis[Y]==1)
						now= now*up[Y]%mo;
				}
			}
			while (l<x){
				//del(l);
				for (I= 1;I<=C[l];I++){
					Y= B[l][I];
					vis[Y]--;
					if (vis[Y]==0)
						now= now*down[Y]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (I= 1;I<=C[r];I++){
					Y= B[r][I];
					vis[Y]--;
					if (vis[Y]==0)
						now= now*down[Y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);//
				for (I= 1;I<=C[r];I++){
					Y= B[r][I];
					vis[Y]++;
					if (vis[Y]==1)
						now= now*up[Y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%lld\n",(ans[i]+mo)%mo);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = (int) 1e6 + 6;
const int mod  = (int) 1e9 + 7;

ll S[maxn], pos[maxn];
vector<pair<int, int> > q[maxn];
ll ans[maxn];
int n, m, a[maxn], d[maxn];
ll IT[maxn];

void update(int k, int l, int r, int x, ll val)
{
    if(l > x || r < x || l > r) return ;
    if(l == r && l == x)
    {
        IT[k] *= val;
        IT[k] %= mod;
        return ;
    }
    int mid = (l + r) >> 1;
    update(2 * k, l, mid, x, val);
    update(2 * k + 1, mid + 1, r, x, val);
    IT[k] = (IT[2 * k] * IT[2 * k + 1]) % mod;
}

ll get(int k, int l, int r, int x, int y)
{
    if(l > r || x > y || x > r || y < l) return 1;
    if(x <= l && r <= y) return IT[k];
    int mid = (l + r) >> 1;
    return get(2 * k, l, mid, x, y) * get(2 * k + 1, mid + 1, r, x, y) % mod;
}

void sieve()
{
    d[1] = 1;
    for (int i = 2; i < maxn; i ++)
    {
        if(d[i]) continue;
        d[i] = i;
        for (int j = i + i; j < maxn; j += i) d[j] = i;
    }
}

ll pw(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll x)
{
    return pw(x, mod - 2);
}

int main()
{
    ///freopen("test.txt", "r", stdin);

    sieve();
    for (int i = 0; i < maxn; i ++) IT[i] = 1;

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) scanf("%d", a + i);
    scanf("%d", &m);
    for (int i = 0; i < m; i ++)
    {
        int l, r; scanf("%d %d", &l, &r);
        q[r].push_back(make_pair(l, i));
    }
    S[0] = 1;
    for (int i = 1; i <= n; i ++)
    {
        S[i] = S[i - 1] * a[i] % mod;
        while (a[i] > 1)
        {
            int x = d[a[i]];
            ll tmp;
            if(pos[x])
            {
                tmp = x * inv(x - 1) % mod;
                update(1, 1, n, pos[x], tmp);
            }
            pos[x] = i;
            tmp = (x - 1) * inv(x) % mod;
            update(1, 1, n, pos[x], tmp);

            while (a[i] % x == 0) a[i] /= x;
        }
        for (int j = 0; j < q[i].size(); j ++)
        {
            int l = q[i][j].first, r = i, id = q[i][j].second;
            ans[id] = ((S[r] * inv(S[l - 1])) % mod) * get(1, 1, n, l, r) % mod;
        }
    }
    for (int i = 0; i < m; i ++) printf("%I64d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = (int) 1e6 + 6;
const int mod  = (int) 1e9 + 7;

ll S[maxn], pos[maxn];
vector<pair<int, int> > q[maxn];
ll ans[maxn];
int n, m, a[maxn], d[maxn];
ll IT[maxn];

void update(int k, int l, int r, int x, ll val)
{
    if(l > x || r < x || l > r) return ;
    if(l == r && l == x)
    {
        IT[k] *= val;
        IT[k] %= mod;
        return ;
    }
    int mid = (l + r) >> 1;
    update(2 * k, l, mid, x, val);
    update(2 * k + 1, mid + 1, r, x, val);
    IT[k] = (IT[2 * k] * IT[2 * k + 1]) % mod;
}

ll get(int k, int l, int r, int x, int y)
{
    if(l > r || x > y || x > r || y < l) return 1;
    if(x <= l && r <= y) return IT[k];
    int mid = (l + r) >> 1;
    return get(2 * k, l, mid, x, y) * get(2 * k + 1, mid + 1, r, x, y) % mod;
}

void sieve()
{
    d[1] = 1;
    for (int i = 2; i < maxn; i ++)
    {
        if(d[i]) continue;
        d[i] = i;
        for (int j = i + i; j < maxn; j += i) d[j] = i;
    }
}

ll pw(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll x)
{
    return pw(x, mod - 2);
}

int main()
{
    ///freopen("test.txt", "r", stdin);

    sieve();
    for (int i = 0; i < maxn; i ++) IT[i] = 1;

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) scanf("%d", a + i);
    scanf("%d", &m);
    for (int i = 0; i < m; i ++)
    {
        int l, r; scanf("%d %d", &l, &r);
        q[r].push_back(make_pair(l, i));
    }
    S[0] = 1;
    for (int i = 1; i <= n; i ++)
    {
        S[i] = S[i - 1] * a[i] % mod;
        while (a[i] > 1)
        {
            int x = d[a[i]];
            if(pos[x])
            {
                update(1, 1, n, pos[x], x);
                update(1, 1, n, pos[x], inv(x - 1));
            }
            pos[x] = i;
            update(1, 1, n, pos[x], inv(x));
            update(1, 1, n, pos[x], x - 1);

            while (a[i] % x == 0) a[i] /= x;
        }
        for (int j = 0; j < q[i].size(); j ++)
        {
            int l = q[i][j].first, r = i, id = q[i][j].second;
            ans[id] = ((S[r] * inv(S[l - 1])) % mod) * get(1, 1, n, l, r) % mod;
        }
    }
    for (int i = 0; i < m; i ++) printf("%I64d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = (int) 1e6 + 6;
const int mod  = (int) 1e9 + 7;

ll S[maxn], pos[maxn];
vector<pair<int, int> > q[maxn];
ll ans[maxn];
int n, m, a[maxn], d[maxn];
ll IT[maxn];

void update(int k, int l, int r, int x, ll val)
{
    if(l > x || r < x || l > r) return ;
    if(l == r && l == x)
    {
        IT[k] *= val;
        IT[k] %= mod;
        return ;
    }
    int mid = (l + r) >> 1;
    update(2 * k, l, mid, x, val);
    update(2 * k + 1, mid + 1, r, x, val);
    IT[k] = (IT[2 * k] * IT[2 * k + 1]) % mod;
}

ll get(int k, int l, int r, int x, int y)
{
    if(l > r || x > y || x > r || y < l) return 1;
    if(x <= l && r <= y) return IT[k];
    int mid = (l + r) >> 1;
    return get(2 * k, l, mid, x, y) * get(2 * k + 1, mid + 1, r, x, y) % mod;
}

void sieve()
{
    d[1] = 1;
    for (int i = 2; i < maxn; i ++)
    {
        if(d[i]) continue;
        d[i] = i;
        for (int j = i + i; j < maxn; j += i) d[j] = i;
    }
}

ll pw(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll x)
{
    return pw(x, mod - 2);
}

int main()
{
    ///freopen("test.txt", "r", stdin);

    sieve();
    for (int i = 0; i < maxn; i ++) IT[i] = 1;

    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) scanf("%d", a + i);
    scanf("%d", &m);
    for (int i = 0; i < m; i ++)
    {
        int l, r; scanf("%d %d", &l, &r);
        q[r].push_back(make_pair(l, i));
    }
    S[0] = 1;
    for (int i = 1; i <= n; i ++)
    {
        S[i] = S[i - 1] * a[i] % mod;
        vector<int> p;
        while (a[i] > 1)
        {
            p.push_back(d[a[i]]);
            a[i] /= d[a[i]];
        }
        sort(p.begin(), p.end());
        p.resize(unique(p.begin(), p.end()) - p.begin());
        for (int j = 0; j < p.size(); j ++)
        {
            int x = p[j];
            ///cout << x << ' ';

            if(pos[x])
            {
                update(1, 1, n, pos[x], x);
                update(1, 1, n, pos[x], inv(x - 1));
            }
            pos[x] = i;
            update(1, 1, n, pos[x], inv(x));
            update(1, 1, n, pos[x], x - 1);
        }
        ///cout << endl;
        for (int j = 0; j < q[i].size(); j ++)
        {
            int l = q[i][j].first, r = i, id = q[i][j].second;
            ans[id] = ((S[r] * inv(S[l - 1])) % mod) * get(1, 1, n, l, r) % mod;
        }
    }
    for (int i = 0; i < m; i ++) printf("%I64d\n", ans[i]);
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = (int) 1e6 + 6;
const int mod  = (int) 1e9 + 7;

ll n, m, a[maxn], S[maxn], pos[maxn];
vector<pair<int, int> > q[maxn];
ll ans[maxn];
int d[maxn];
ll IT[maxn];

void update(int k, int l, int r, int x, ll val)
{
    if(l > x || r < x || l > r) return ;
    if(l == r && l == x)
    {
        IT[k] *= val;
        IT[k] %= mod;
        return ;
    }
    int mid = (l + r) >> 1;
    update(2 * k, l, mid, x, val);
    update(2 * k + 1, mid + 1, r, x, val);
    IT[k] = (IT[2 * k] * IT[2 * k + 1]) % mod;
}

ll get(int k, int l, int r, int x, int y)
{
    if(l > r || x > y || x > r || y < l) return 1;
    if(x <= l && r <= y) return IT[k];
    int mid = (l + r) >> 1;
    return get(2 * k, l, mid, x, y) * get(2 * k + 1, mid + 1, r, x, y) % mod;
}

void sieve()
{
    d[1] = 1;
    for (int i = 2; i < maxn; i ++)
    {
        if(d[i]) continue;
        d[i] = i;
        for (int j = i + i; j < maxn; j += i) d[j] = i;
    }
}

ll pw(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll x)
{
    return pw(x, mod - 2);
}

int main()
{
    ///freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0);

    sieve();
    for (int i = 0; i < maxn; i ++) IT[i] = 1;

    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    cin >> m;
    for (int i = 0; i < m; i ++)
    {
        int l, r; cin >> l >> r;
        q[r].push_back(make_pair(l, i));
    }
    S[0] = 1;
    for (int i = 1; i <= n; i ++)
    {
        S[i] = S[i - 1] * a[i] % mod;
        vector<int> p;
        while (a[i] > 1)
        {
            p.push_back(d[a[i]]);
            a[i] /= d[a[i]];
        }
        sort(p.begin(), p.end());
        p.resize(unique(p.begin(), p.end()) - p.begin());
        for (int j = 0; j < p.size(); j ++)
        {
            int x = p[j];
            ///cout << x << ' ';

            if(pos[x])
            {
                update(1, 1, n, pos[x], x);
                update(1, 1, n, pos[x], inv(x - 1));
            }
            pos[x] = i;
            update(1, 1, n, pos[x], inv(x));
            update(1, 1, n, pos[x], x - 1);
        }
        ///cout << endl;
        for (int j = 0; j < q[i].size(); j ++)
        {
            int l = q[i][j].first, r = i, id = q[i][j].second;
            ans[id] = ((S[r] * inv(S[l - 1])) % mod) * get(1, 1, n, l, r) % mod;
        }
    }
    for (int i = 0; i < m; i ++) cout << ans[i] << "\n";
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
using namespace std;

bool isdigit(char c) {return c>='0' && c<='9';}
int qread()
{
	char c;int s=0,t=1;while (!isdigit(c=getchar())) (c=='-' && (t=-1));
	do s=s*10+c-'0'; while (isdigit(c=getchar()));return s*t;
}

int n,m;
#define maxn 200011
const int mod=1e9+7;
struct BIT
{
	int a[maxn];
	void clear(int n) {for (int i=1;i<=n;i++) a[i]=1;}
	void mul(int x,int v) {for (;x<=n;x+=x&-x) a[x]=(1ll*a[x]*v)%mod;}
	int query(int x) {int ans=1;for (;x;x-=x&-x) ans=1ll*ans*a[x]%mod;return ans;}
}t,tt,ttt;
int a[maxn],last[maxn*10];
int powmod(int a,int b)
{
	a%=mod;int ans=1;
	while (b)
	{
		if (b&1) ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
int ans[maxn];
struct ques
{
	int l,r,id;
	bool operator < (const ques &b) const {return r<b.r;}
}q[maxn];
void play(int j)
{
	ans[q[j].id]=1ll*ttt.query(q[j].r)*powmod(ttt.query(q[j].l-1),mod-2)%mod*powmod(t.query(q[j].r),mod-2)%mod
	*t.query(q[j].l-1)%mod*tt.query(q[j].r)%mod*powmod(tt.query(q[j].l-1),mod-2)%mod;
}
int main()
{
	n=qread();t.clear(n);tt.clear(n);ttt.clear(n);
	for (int i=1;i<=n;i++) a[i]=qread();
	m=qread();
	for (int i=1;i<=m;i++) q[i].id = i, q[i].l=qread(),q[i].r=qread();
	sort(q+1,q+1+m);
	int j=1;
	for (int i=1;i<=n;i++)
	{
		ttt.mul(i,a[i]);
		for (int k=2;1ll*k*k<=a[i];k++) if (!(a[i]%k))
		{
			if (last[k]) t.mul(last[k],powmod(k,mod-2)),tt.mul(last[k],powmod(k-1,mod-2));
			t.mul(i,k), tt.mul(i,k-1);
			while (!(a[i]%k)) a[i]/=k;
			last[k]=i;
		}
		if (a[i]>1)
		{
			if (last[a[i]]) t.mul(last[a[i]],powmod(a[i],mod-2)),tt.mul(last[a[i]],powmod(a[i]-1,mod-2));
			t.mul(i,a[i]), tt.mul(i,a[i]-1);
			last[a[i]]=i;
		}
//		for (int k=1;k<=10;k++) cout<<last[k]<<' ';cout<<"last"<<endl;
		while (j<=m && q[j].r==i) play(j++);
//		for (int k=1;k<=10;k++) cout<<ttt.query(k)<<' ';cout<<"ttt"<<endl;
	}
	for (int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>

using namespace std;

typedef long long LL;

const int lim=1e6;
bool flag[lim+5];
int p[lim+5],num;
int minp[lim+5];
int n,x[200005];
int dqx,now;
vector<int> v[200005];
vector<int> vx[lim+5];
struct Node
{
    int l,r,id;
    bool operator < (const Node &a) const
    {
        return l<a.l;
    }
}f[200005];
int ans[200005];
int ny[lim+5];
const int mod=1e9+7;
int c[200005];
int m,dq;
int lowbit(int x)
{
    return x&(-x);
}
void add(int x,int y)
{
    for (int i=x;i<=n;i+=lowbit(i))
    {
        c[i]=1LL*c[i]*y%mod;
    }
}
int query(int x)
{
    int ans=1;
    for (int i=x;i>=1;i-=lowbit(i))
    {
        ans=1LL*c[i]*ans%mod;
    }
    return ans;
}
int powmod(int a,int b,int c)
{
    int ans=1;
    while (b)
    {
        if (b%2==1) ans=1LL*ans*a%c;
        b/=2;
        a=1LL*a*a%c;
    }
    return ans;
}
void prework()

{

    memset(flag,true,sizeof(flag));

    flag[0]=flag[1]=false;

    num=0;

    for (int i=2;i<=lim;++i)

    {

        if (flag[i])

        {

            ++num;p[num]=i;minp[i]=num;

        }

        for (int j=1;j<=num;++j)

        {

            if (i*p[j]>lim) break;

            flag[i*p[j]]=false;

            minp[i*p[j]]=j;

            if (i%p[j]==0) break;

        }

    }

}

int main()

{

    prework();
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",&x[i]);
    for (int i=1;i<=n;++i)
    {
        v[i].clear();
        dqx=x[i];
        while (dqx!=1)
        {
            v[i].push_back(minp[dqx]);
            vx[minp[dqx]].push_back(i);
            now=minp[dqx];
            while (minp[dqx]==now) dqx/=p[now];
        }
    }
    for (int i=1;i<=num;++i) reverse(vx[i].begin(),vx[i].end());
    memset(c,0,sizeof(c));
    for (int i=1;i<=lim;++i) ny[i]=powmod(i,mod-2,mod);
    scanf("%d",&m);
    for (int i=1;i<=m;++i)
    {
        scanf("%d%d",&f[i].l,&f[i].r);
        f[i].id=i;
    }
    sort(f+1,f+m+1);
    for (int i=1;i<=n;++i) c[i]=1;
    for (int i=1;i<=n;++i)
    {
        add(i,x[i]);
        for (int j=0;j<v[i].size();++j)
        {
            if (vx[v[i][j]].back()==i)
                add(i,1LL*(p[v[i][j]]-1)*ny[p[v[i][j]]]%mod);
        }
    }
    dq=1;
    for (int i=1;i<=n;++i)
    {
        while (dq<=m&&f[dq].l==i)
        {
            ans[f[dq].id]=query(f[dq].r);
            ++dq;
        }
        add(i,ny[x[i]]);
        for (int j=0;j<v[i].size();++j)
        {
            add(i,1LL*p[v[i][j]]*ny[p[v[i][j]]-1]%mod);
            vx[v[i][j]].pop_back();
            if (vx[v[i][j]].size()>0)
            {
                add(vx[v[i][j]].back(),1LL*(p[v[i][j]]-1)*ny[p[v[i][j]]]%mod);
            }
        }
    }
    for (int i=1;i<=m;++i) cout<<ans[i]<<endl;
    return 0;

}


#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>

using namespace std;

typedef long long LL;

const int lim=1e6;

bool flag[lim+5];

int num;

int p[lim+5];

int minp[lim+5];

int n,x[200005];
const int mod=1e9+7;
int pp[lim+5];
int cnt[lim+5];
int nn,m;
struct Node
{
    int id,cnt;
}dq;
vector<Node> v[200005];
struct Node2
{
    int l,r,id;
}f[200005];
int ans[200005];
int now;
int pp2[lim+5];
int x2[200005];
int l,r;
int powmod(int a,int b,int c)
{
    int ans=1;
    while (b)
    {
        if (b&1) ans=1LL*ans*a%c;
        b/=2;
        a=1LL*a*a%c;
    }
    return ans;
}
bool cmp(Node2 a,Node2 b)
{
    if (a.l/nn==b.l/nn) return a.r<b.r;
    return a.l<b.l;
}
void prework()

{

    memset(flag,true,sizeof(flag));

    flag[0]=flag[1]=false;

    num=0;

    for (int i=2;i<=lim;++i)

    {

        if (flag[i])

        {

            ++num;p[num]=i;minp[i]=num;

        }

        for (int j=1;j<=num;++j)

        {

            if (i*p[j]>lim) break;

            flag[i*p[j]]=false;

            minp[i*p[j]]=j;

            if (i%p[j]==0) break;

        }

    }

}

int main()

{

    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",&x[i]);
    prework();
    for (int i=1;i<=num;++i) pp[i]=powmod(p[i],mod-2,mod);
    for (int i=1;i<=num;++i) pp2[i]=powmod(p[i]-1,mod-2,mod);
    for (int i=1;i<=n;++i) x2[i]=powmod(x[i],mod-2,mod);

    memset(cnt,0,sizeof(cnt));
    for (int i=1;i<=n;++i)
    {
        v[i].clear();
        int dqx=x[i];
        while (dqx!=1)
        {
            int now,dqs;
            now=minp[dqx];dqs=0;
            while (minp[dqx]==now)
            {
                dqs++;dqx/=p[now];
            }
            dq.id=now;dq.cnt=dqs;
            v[i].push_back(dq);
        }
    }
    scanf("%d",&m);
    for (int i=1;i<=m;++i)
    {
        scanf("%d%d",&f[i].l,&f[i].r);
        f[i].id=i;
    }
    nn=(int)sqrt(1.0*n);
    sort(f+1,f+m+1,cmp);
    int dql,dqr;
    dql=1;dqr=0;now=1;
    for (int i=1;i<=m;++i)
    {
        l=f[i].l;
        r=f[i].r;
        if (dqr<r)
        {
            for (int j=dqr+1;j<=r;++j)
            {
                now=1LL*now*x[j]%mod;
                for (int k=0;k<v[j].size();++k)
                {
                    if (cnt[v[j][k].id]==0) now=1LL*now*(p[v[j][k].id]-1)%mod*pp[v[j][k].id]%mod;
                    cnt[v[j][k].id]+=v[j][k].cnt;
                }
            }
            dqr=r;
        }
        if (l<dql)
        {
            for (int j=l;j<=dql-1;++j)
            {
                now=1LL*now*x[j]%mod;
                for (int k=0;k<v[j].size();++k)
                {
                    if (cnt[v[j][k].id]==0) now=1LL*now*(p[v[j][k].id]-1)%mod*pp[v[j][k].id]%mod;
                    cnt[v[j][k].id]+=v[j][k].cnt;
                }
            }
            dql=l;
        }
        if (r<dqr)
        {
            for (int j=r+1;j<=dqr;++j)
            {
                now=1LL*now*x2[j]%mod;
                for (int k=0;k<v[j].size();++k)
                {
                    cnt[v[j][k].id]-=v[j][k].cnt;
                    if (cnt[v[j][k].id]==0) now=1LL*now*(pp2[v[j][k].id])%mod*p[v[j][k].id]%mod;
                }
            }
            dqr=r;
        }
        if (dql<l)
        {
            for (int j=dql;j<=l-1;++j)
            {
                now=1LL*now*x2[j]%mod;
                for (int k=0;k<v[j].size();++k)
                {
                    cnt[v[j][k].id]-=v[j][k].cnt;
                    if (cnt[v[j][k].id]==0) now=1LL*now*(pp2[v[j][k].id])%mod*p[v[j][k].id]%mod;
                }
            }
            dql=l;
        }
        ans[f[i].id]=now;
    }
    for (int i=1;i<=m;++i) printf("%d\n",ans[i]);
    return 0;

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using std::vector;
typedef long long ll;
const ll mo=1000000007;
ll pow(ll x,int y){
	if(!y)return 1;
	ll u=pow(x,y>>1);
	if(y&1)return u*u%mo*x%mo;
		else return u*u%mo;
}
const int N=1000010,M=N,S=N;
ll p[M],x,a[N],xb,n,qq,sz,m,ans[N],mi[S],ji[N],inv[N],pp[M],lst[M];
int i,l,r,j;
unsigned int k;
bool b[S];
struct query{
	int l,id;
};
vector<query> q[N];
struct segtree{
	struct node{
		int l,r,m;
		ll v;
	}a[N<<2];
	void build(int i,int l,int r){
		a[i].l=l;
		a[i].r=r;
		a[i].m=(l+r)>>1;
		a[i].v=1;
		if(l==r)return;
		build(i<<1,l,a[i].m);
		build(i<<1|1,a[i].m+1,r);
	}
	void add(int i,int l,int r,ll x){
		if(a[i].l==l && a[i].r==r){
			a[i].v=a[i].v*x%mo;
			return;
		}
		if(l>a[i].m)add(i<<1|1,l,r,x);
			else if(r<=a[i].m)add(i<<1,l,r,x);
					else{
						add(i<<1,l,a[i].m,x);
						add(i<<1|1,a[i].m+1,r,x);
					}
	}
	inline ll query(int l){
		int i=1;
		ll ans=1;
		for(;a[i].l!=a[i].r;l>a[i].m?i=i<<1|1:i<<=1)
			ans=ans*a[i].v%mo;
		return ans*a[i].v%mo;
	}
}T;
int main(){
	scanf("%lld",&n);
	inv[0]=ji[0]=1;
	for(i=1;i<=n;++i){
		scanf("%lld",a+i);
		if(a[i]>m)m=a[i];
		ji[i]=ji[i-1]*a[i]%mo;
		inv[i]=inv[i-1]*pow(a[i],mo-2)%mo;
	}
	scanf("%lld",&qq);
	for(i=1;i<=qq;++i){
		scanf("%d%d",&l,&r);
		q[r].push_back((query){l,i});
	}
	for(i=2;i<=m;++i){
		if(!b[i])p[mi[i]=++xb]=i;
		for(j=1;j<=xb;++j){
			x=p[j]*i;
			if(x>m)break;
			b[x]=1;
			mi[x]=j;
			if(i%p[j]==0)break;
		}
	}
	for(i=1;i<=xb;++i)pp[i]=(p[i]-1)*pow(p[i],mo-2)%mo;
	T.build(1,1,n);
	for(i=1;i<=n;++i){
		x=a[i];
		while(x>1){
			for(j=mi[x];x%p[j]==0;x/=p[j]);
			T.add(1,lst[j]+1,i,pp[j]);
			lst[j]=i;
		}
		for(k=0;k<q[i].size();++k)
			ans[q[i][k].id]=ji[i]*inv[q[i][k].l-1]%mo*T.query(q[i][k].l)%mo;
	}
	for(i=1;i<=qq;++i)printf("%I64\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<cctype>
#include<vector>
using std::vector;
typedef long long ll;
const ll mo=1000000007;
ll pow(ll x,int y){
	if(!y)return 1;
	ll u=pow(x,y>>1);
	if(y&1)return u*u%mo*x%mo;
		else return u*u%mo;
}
const int N=1000010,M=N,S=N;
ll p[M],x,a[N],xb,n,qq,sz,m,ans[N],mi[S],ji[N],inv[N],pp[M],lst[M];
int i,l,r,j;
unsigned int k;
bool b[S];
struct query{
	int l,id;
};
vector<query> q[N];
struct segtree{
	struct node{
		int l,r,m;
		ll v;
	}a[N<<2];
	void build(int i,int l,int r){
		a[i].l=l;
		a[i].r=r;
		a[i].m=(l+r)>>1;
		a[i].v=1;
		if(l==r)return;
		build(i<<1,l,a[i].m);
		build(i<<1|1,a[i].m+1,r);
	}
	void add(int i,int l,int r,ll x){
		if(a[i].l==l && a[i].r==r){
			a[i].v=a[i].v*x%mo;
			return;
		}
		if(l>a[i].m)add(i<<1|1,l,r,x);
			else if(r<=a[i].m)add(i<<1,l,r,x);
					else{
						add(i<<1,l,a[i].m,x);
						add(i<<1|1,a[i].m+1,r,x);
					}
	}
	inline ll query(int l){
		int i=1;
		ll ans=1;
		for(;a[i].l!=a[i].r;l>a[i].m?i=i<<1|1:i<<=1)
			ans=ans*a[i].v%mo;
		return ans*a[i].v%mo;
	}
}T;
inline int getint(){
	int x=0;
	char c=getchar();
	while(!isdigit(c))c=getchar();
	for(;isdigit(c);c=getchar())x=x*10+c-48;
	return x;
}
int buf[10];
inline void putint(int x){
	if(!x)putchar('0');
		else{
			int xb=0;
			for(;x;x/=10)buf[++xb]=x%10;
			for(;xb;--xb)putchar(buf[xb]+48);
		}
}
int main(){
	n=getint();
	inv[0]=ji[0]=1;
	for(i=1;i<=n;++i){
		a[i]=getint();
		if(a[i]>m)m=a[i];
		ji[i]=ji[i-1]*a[i]%mo;
		inv[i]=inv[i-1]*pow(a[i],mo-2)%mo;
	}
	qq=getint();
	for(i=1;i<=qq;++i){
		l=getint();
		r=getint();
		q[r].push_back((query){l,i});
	}
	for(i=2;i<=m;++i){
		if(!b[i])p[mi[i]=++xb]=i;
		for(j=1;j<=xb;++j){
			x=p[j]*i;
			if(x>m)break;
			b[x]=1;
			mi[x]=j;
			if(i%p[j]==0)break;
		}
	}
	for(i=1;i<=xb;++i)pp[i]=(p[i]-1)*pow(p[i],mo-2)%mo;
	T.build(1,1,n);
	for(i=1;i<=n;++i){
		x=a[i];
		while(x>1){
			for(j=mi[x];x%p[j]==0;x/=p[j]);
			T.add(1,lst[j]+1,i,pp[j]);
			lst[j]=i;
		}
		for(k=0;k<q[i].size();++k)
			ans[q[i][k].id]=ji[i]*inv[q[i][k].l-1]%mo*T.query(q[i][k].l)%mo;
	}
	for(i=1;i<=qq;++i)putint(ans[i]),putchar('\n');
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using std::vector;
typedef long long ll;
typedef unsigned int ui;
const ll mo=1000000007;
ll pow(ll x,int y){
	if(!y)return 1;
	ll u=pow(x,y>>1);
	if(y&1)return u*u%mo*x%mo;
		else return u*u%mo;
}
const int N=1000010,M=N,S=N;
ll p[M],x,i,a[N],xb,j,n,qq,sz,m,ans[N],s[M],mi[S],l,r,an,ji[N],inv[N],inp[M],pp[M];
ui k;
bool b[S];
vector<int> v[N];
struct query{
	int l,r,id;
	bool operator<(const query&x)const{
		return l/sz==x.l/sz?r<x.r:l/sz<x.l/sz;
	}
}q[N];
inline void up(int i,int vv){
	for(k=0;k<v[i].size();++k){
		if(vv==-1 && s[v[i][k]]==1)an=an*inp[v[i][k]]%mo;
		if(vv==1 && !s[v[i][k]])an=an*pp[v[i][k]]%mo;
		s[v[i][k]]+=vv;
	}
}
int main(){
	//freopen("b.txt","r",stdin);
	//freopen("bb.txt","w",stdout);
	scanf("%lld",&n);
	sz=sqrt(n);
	inv[0]=ji[0]=1;
	for(i=1;i<=n;++i){
		scanf("%lld",a+i);
		if(a[i]>m)m=a[i];
		ji[i]=ji[i-1]*a[i]%mo;
		inv[i]=inv[i-1]*pow(a[i],mo-2)%mo;
	}
	for(i=2;i<=m;++i){
		if(!b[i])p[mi[i]=++xb]=i;
		for(j=1;j<=xb;++j){
			x=p[j]*i;
			if(x>m)break;
			b[x]=1;
			mi[x]=j;
			if(i%p[j]==0)break;
		}
	}
	for(i=1;i<=xb;++i){
		pp[i]=(p[i]-1)*pow(p[i],mo-2)%mo;
		inp[i]=pow(pp[i],mo-2)%mo;
	}
	for(i=1;i<=n;++i){
		x=a[i];
		while(x>1){
			v[i].push_back(mi[x]);
			for(j=mi[x];x%p[j]==0;x/=p[j]);
		}
	}
	scanf("%lld",&qq);
	for(i=1;i<=qq;++i){
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].id=i;
	}
	std::sort(q+1,q+qq+1);
	an=1;
	l=1;
	r=1;
	up(1,1);
	for(i=1;i<=qq;++i){
		while(l>q[i].l)up(--l,1);
		while(r<q[i].r)up(++r,1);
		while(l<q[i].l)up(l++,-1);
		while(r>q[i].r)up(r--,-1);
		ans[q[i].id]=an*inv[l-1]%mo*ji[r]%mo;
	}
	for(i=1;i<=qq;++i)printf("%I64d\n",ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORd(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define EPS 1e-9
const int mod = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = 2 * acos(0);

const int MAXN = 1000010;
bool flag[MAXN];
int sp[MAXN];
void Sieve() {
	for (int i = 2; i < MAXN; i += 2) sp[i] = 2;
	for (int i = 3; i < MAXN; i += 2) if (!flag[i]) {
		sp[i] = i;
		for (int j = i; 1LL * i * j < MAXN; j += 2) if (!flag[i * j]) {
			flag[i * j] = 1;
			sp[i * j] = i;
		}
	}
}

int inv[MAXN];
void build(int p) {
	inv[1] = 1;
	for (int i = 2; i < MAXN; i++) inv[i] = (p - 1LL * (p / i) * inv[p % i] % p) % p;
}

const int maxn = 200010;
int n, q;
int a[maxn];
vector<pair<pi, int> > query;
int prf[maxn];
int prv[5 * maxn];
int ans[maxn];

int bit[maxn];
void add(int p, int val) {
	for (; p < maxn; p += p & -p) bit[p] = 1LL * bit[p] * val % mod;
}
int get(int p) {
	int res = 1;
	for (; p > 0; p -= p & -p) res = 1LL * res * bit[p] % mod;
	return res;
}

int exp(int n, int k) {
	if (!k) return 1;
	if (k & 1) return 1LL * n * exp(n, k - 1) % mod;
	int t = exp(n, k >> 1);
	return 1LL * t * t % mod;
}

void update(int k) {
	int t = a[k];
	while (t > 1) {
		if (prv[sp[t]] < k) {
			if (prv[sp[t]]) add(prv[sp[t]], 1LL * sp[t] * inv[sp[t] - 1] % mod);
			add(k, 1LL * (sp[t] - 1) * inv[sp[t]] % mod);
			prv[sp[t]] = k;
		}
		t /= sp[t];
	}
}

void solve() {
	Sieve(); build(mod); FOR(i, 0, maxn) bit[i] = 1;
	scanf("%d", &n);
	FOR(i, 1, n + 1) scanf("%d", a + i);
	scanf("%d", &q);
	FOR(i, 0, q) {
		int l, r; scanf("%d%d", &l, &r);
		query.pb(mp(mp(r, l), i));
	}
	sort(all(query));
	int cur = 1; prf[0] = 1;
	FOR(i, 0, q) {
		while (cur <= query[i].fi.fi) {
			update(cur);
			prf[cur] = 1LL * prf[cur - 1] * a[cur] % mod;
			cur++;
		}
		ans[query[i].se] = 1LL * get(query[i].fi.fi) * exp(get(query[i].fi.se - 1), mod - 2) % mod;
		ans[query[i].se] = 1LL * ans[query[i].se] * prf[query[i].fi.fi] % mod * exp(prf[query[i].fi.se - 1], mod - 2) % mod;
	}
	FOR(i, 0, q) printf("%d\n", ans[i]);
}

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(NULL);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORd(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define EPS 1e-9
const int mod = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = 2 * acos(0);

const int MAXN = 1000010;
bool flag[MAXN];
int sp[MAXN];
void Sieve() {
	for (int i = 2; i < MAXN; i += 2) sp[i] = 2;
	for (int i = 3; i < MAXN; i += 2) if (!flag[i]) {
		sp[i] = i;
		for (int j = i; 1LL * i * j < MAXN; j += 2) if (!flag[i * j]) {
			flag[i * j] = 1;
			sp[i * j] = i;
		}
	}
}

const int maxn = 200010;
const int R = (int) sqrt(maxn) + 10;
int n;
int a[maxn];
int c[maxn];
vector<pair<pi, int> > query;
int ans[maxn];

int exp(int n, int k) {
	if (!k) return 1;
	if (k & 1) return 1LL * n * exp(n, k - 1) % mod;
	int t = exp(n, k >> 1);
	return 1LL * t * t % mod;
}

bool compare(pair<pi, int> a, pair<pi, int> b) {
	if (a.fi.fi / R != b.fi.fi / R) return a.fi.fi / R < b.fi.fi / R;
	return a.fi.se < b.fi.se;
}

void add(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (c[sp[t]]++ > 0) cur = 1LL * cur * sp[t] % mod;
		else cur = 1LL * cur * (sp[t] - 1) % mod;
		t /= sp[t];
	}
}

void remove(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (--c[sp[t]] > 0) cur = 1LL * cur * exp(sp[t], mod - 2) % mod;
		else cur = 1LL * cur * exp(sp[t] - 1, mod - 2) % mod;
		t /= sp[t];
	}
}

void solve() {
	Sieve();
	scanf("%d", &n);
	FOR(i, 0, n) scanf("%d", a + i);
	int q; scanf("%d", &q);
	FOR(i, 0, q) {
		int l, r; scanf("%d%d", &l, &r); l--; r--;
		query.pb(mp(mp(l, r), i));
	}
	sort(all(query), compare);
	pi prv = mp(-1, -1);
	int cur = 1;
	FOR(i, 0, sz(query)) {
		int u = query[i].fi.fi;
		int v = query[i].fi.se;
		if (u >= prv.fi) {
			FOR(j, prv.fi, min(prv.se + 1, u)) remove(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		else {
			FOR(j, u, min(prv.fi, v + 1)) add(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		ans[query[i].se] = cur;
		prv = query[i].fi;
	}
	FOR(i, 0, q) printf("%d\n", ans[i]);
}

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(NULL);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORd(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define EPS 1e-9
const int mod = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = 2 * acos(0);

const int MAXN = 1000010;
bool flag[MAXN];
int sp[MAXN];
void Sieve() {
	for (int i = 2; i < MAXN; i += 2) sp[i] = 2;
	for (int i = 3; i < MAXN; i += 2) if (!flag[i]) {
		sp[i] = i;
		for (int j = i; 1LL * i * j < MAXN; j += 2) if (!flag[i * j]) {
			flag[i * j] = 1;
			sp[i * j] = i;
		}
	}
}

const int maxn = 200010;
const int R = (int) sqrt(maxn) + 10;
int n;
int a[maxn];
int c[5 * maxn];
vector<pair<pi, int> > query;
int ans[maxn];

int exp(int n, int k) {
	if (!k) return 1;
	if (k & 1) return 1LL * n * exp(n, k - 1) % mod;
	int t = exp(n, k >> 1);
	return 1LL * t * t % mod;
}

bool compare(pair<pi, int> a, pair<pi, int> b) {
	if (a.fi.fi / R != b.fi.fi / R) return a.fi.fi / R < b.fi.fi / R;
	return a.fi.se < b.fi.se;
}

void add(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (c[sp[t]]++ > 0) cur = 1LL * cur * sp[t] % mod;
		else cur = 1LL * cur * (sp[t] - 1) % mod;
		t /= sp[t];
	}
}

void remove(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (--c[sp[t]] > 0) cur = 1LL * cur * exp(sp[t], mod - 2) % mod;
		else cur = 1LL * cur * exp(sp[t] - 1, mod - 2) % mod;
		t /= sp[t];
	}
}

void solve() {
	Sieve();
	scanf("%d", &n);
	FOR(i, 0, n) scanf("%d", a + i);
	int q; scanf("%d", &q);
	FOR(i, 0, q) {
		int l, r; scanf("%d%d", &l, &r); l--; r--;
		query.pb(mp(mp(l, r), i));
	}
	sort(all(query), compare);
	pi prv = mp(-1, -1);
	int cur = 1;
	FOR(i, 0, sz(query)) {
		int u = query[i].fi.fi;
		int v = query[i].fi.se;
		if (u >= prv.fi) {
			FOR(j, prv.fi, min(prv.se + 1, u)) remove(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		else {
			FOR(j, u, min(prv.fi, v + 1)) add(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		ans[query[i].se] = cur;
		prv = query[i].fi;
	}
	FOR(i, 0, q) printf("%d\n", ans[i]);
}

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(NULL);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORd(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define EPS 1e-9
const int mod = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = 2 * acos(0);

const int MAXN = 1000010;
bool flag[MAXN];
int sp[MAXN];
void Sieve() {
	for (int i = 2; i < MAXN; i += 2) sp[i] = 2;
	for (int i = 3; i < MAXN; i += 2) if (!flag[i]) {
		sp[i] = i;
		for (int j = i; 1LL * i * j < MAXN; j += 2) if (!flag[i * j]) {
			flag[i * j] = 1;
			sp[i * j] = i;
		}
	}
}

const int maxn = 200010;
const int R = (int) sqrt(maxn) + 10;
int n;
int a[maxn];
int c[5 * maxn];
int inv[5 * maxn];
vector<pair<pi, int> > query;
int ans[maxn];

int exp(int n, int k) {
	if (!k) return 1;
	if (k & 1) return 1LL * n * exp(n, k - 1) % mod;
	int t = exp(n, k >> 1);
	return 1LL * t * t % mod;
}

bool compare(pair<pi, int> a, pair<pi, int> b) {
	if (a.fi.fi / R != b.fi.fi / R) return a.fi.fi / R < b.fi.fi / R;
	return a.fi.se < b.fi.se;
}

void add(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (c[sp[t]]++ > 0) cur = 1LL * cur * sp[t] % mod;
		else cur = 1LL * cur * (sp[t] - 1) % mod;
		t /= sp[t];
	}
}

void remove(int& cur, int i) {
	int t = a[i];
	while (t > 1) {
		if (--c[sp[t]] > 0) cur = 1LL * cur * inv[sp[t]] % mod;
		else cur = 1LL * cur * inv[sp[t] - 1] % mod;
		t /= sp[t];
	}
}

void solve() {
	Sieve(); FOR(i, 1, 5 * maxn) inv[i] = exp(i, mod - 2);
	scanf("%d", &n);
	FOR(i, 0, n) scanf("%d", a + i);
	int q; scanf("%d", &q);
	FOR(i, 0, q) {
		int l, r; scanf("%d%d", &l, &r); l--; r--;
		query.pb(mp(mp(l, r), i));
	}
	sort(all(query), compare);
	pi prv = mp(-1, -1);
	int cur = 1;
	FOR(i, 0, sz(query)) {
		int u = query[i].fi.fi;
		int v = query[i].fi.se;
		if (u >= prv.fi) {
			FOR(j, prv.fi, min(prv.se + 1, u)) remove(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		else {
			FOR(j, u, min(prv.fi, v + 1)) add(cur, j);
			if (v <= prv.se) FOR(j, v + 1, prv.se + 1) remove(cur, j);
			else FOR(j, max(u, prv.se + 1), v + 1) add(cur, j);
		}
		ans[query[i].se] = cur;
		prv = query[i].fi;
	}
	FOR(i, 0, q) printf("%d\n", ans[i]);
}

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(NULL);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int blocknum;
int prime[1001],isprime[1001];
int num[200001];
int p[200001][8],cnt[200001];
int nowcnt[1000001];
long long ni[1000001];
bool cmp1(query a,query b)
{
    if(a.l/blocknum==b.l/blocknum)return a.r<b.r;
    return a.l<b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000;i++)
    {
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(int j=i*i;j<=1000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
    }
    int n;
    scanf("%d",&n);
    blocknum=sqrt(n+0.5)+1;
    int a;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        num[i]=a;
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                p[i][cnt[i]++]=prime[j];
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)p[i][cnt[i]++]=a;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int l=1,r=0;
    long long ans=1;
    for(int i=0;i<q;i++)
    {
        while(r<que[i].r)
        {
            r++;
            ans=(ans*num[r])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        while(r>que[i].r)
        {
            ans=(ans*ni[num[r]])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            r--;
        }
        while(l<que[i].l)
        {
            ans=(ans*ni[num[l]])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            l++;
        }
        while(l>que[i].l)
        {
            l--;
            ans=(ans*num[l])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        que[i].ans=ans;
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int blocknum;
int prime[100001],isprime[1000001];
int num[200001];
int p[200001][8],cnt[200001];
int nowcnt[1000001];
long long ni[1000001];
bool cmp1(query a,query b)
{
    if(a.l/blocknum==b.l/blocknum)return a.r<b.r;
    return a.l<b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000;i++)
    {
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(int j=i*i;j<=1000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
    }
    int n;
    scanf("%d",&n);
    blocknum=sqrt(n+0.5);
    int a;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        num[i]=a;
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                p[i][cnt[i]++]=prime[j];
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)p[i][cnt[i]++]=a;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int l=1,r=0;
    long long ans=1;
    for(int i=0;i<q;i++)
    {
        while(r<que[i].r)
        {
            r++;
            ans=(ans*num[r])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        while(r>que[i].r)
        {
            ans=(ans*ni[num[r]])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            r--;
        }
        while(l<que[i].l)
        {
            ans=(ans*ni[num[l]])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            l++;
        }
        while(l>que[i].l)
        {
            l--;
            ans=(ans*num[l])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        que[i].ans=ans;
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int blocknum;
int prime[1001],isprime[1001];
int num[200001];
int p[200001][8],cnt[200001];
int nowcnt[1000001];
long long ni[1000001];
bool cmp1(query a,query b)
{
    if(a.l/blocknum==b.l/blocknum)return a.r<b.r;
    return a.l<b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000;i++)
    {
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(int j=i*i;j<=1000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
    }
    int n;
    scanf("%d",&n);
    blocknum=sqrt(n+0.5)-1;
    int a;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        num[i]=a;
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                p[i][cnt[i]++]=prime[j];
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)p[i][cnt[i]++]=a;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int l=1,r=0;
    long long ans=1;
    for(int i=0;i<q;i++)
    {
        while(r<que[i].r)
        {
            r++;
            ans=(ans*num[r])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        while(r>que[i].r)
        {
            ans=(ans*ni[num[r]])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            r--;
        }
        while(l<que[i].l)
        {
            ans=(ans*ni[num[l]])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            l++;
        }
        while(l>que[i].l)
        {
            l--;
            ans=(ans*num[l])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        que[i].ans=ans;
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int blocknum;
int prime[100001],isprime[1000001];
int num[200001];
int p[200001][8],cnt[200001];
int nowcnt[1000001];
long long ni[1000001];
bool cmp1(query a,query b)
{
    if(a.l/blocknum==b.l/blocknum)return a.r<b.r;
    return a.l<b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(long long j=(long long)i*i;j<=1000000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    int n;
    scanf("%d",&n);
    blocknum=sqrt(n+0.5);
    int a;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        num[i]=a;
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                p[i][cnt[i]++]=prime[j];
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)p[i][cnt[i]++]=a;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int l=1,r=0;
    long long ans=1;
    for(int i=0;i<q;i++)
    {
        while(r<que[i].r)
        {
            r++;
            ans=(ans*num[r])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        while(r>que[i].r)
        {
            ans=(ans*ni[num[r]])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            r--;
        }
        while(l<que[i].l)
        {
            ans=(ans*ni[num[l]])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            l++;
        }
        while(l>que[i].l)
        {
            l--;
            ans=(ans*num[l])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        que[i].ans=ans;
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int blocknum;
int prime[1001],isprime[1001];
int num[200001];
int p[200001][8],cnt[200001];
int nowcnt[1000001];
long long ni[1000001];
bool cmp1(query a,query b)
{
    if(a.l/blocknum==b.l/blocknum)return a.r<b.r;
    return a.l<b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000;i++)
    {
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(int j=i*i;j<=1000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
    }
    int n;
    scanf("%d",&n);
    blocknum=sqrt(sqrt(n+0.5));
    int a;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        num[i]=a;
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                p[i][cnt[i]++]=prime[j];
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)p[i][cnt[i]++]=a;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int l=1,r=0;
    long long ans=1;
    for(int i=0;i<q;i++)
    {
        while(r<que[i].r)
        {
            r++;
            ans=(ans*num[r])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        while(r>que[i].r)
        {
            ans=(ans*ni[num[r]])%1000000007;
            for(int j=0;j<cnt[r];j++)
            {
                int now=p[r][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            r--;
        }
        while(l<que[i].l)
        {
            ans=(ans*ni[num[l]])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                nowcnt[now]--;
                if(nowcnt[now]==0)
                {
                    ans=(ans*now)%1000000007;
                    ans=(ans*ni[now-1])%1000000007;
                }
            }
            l++;
        }
        while(l>que[i].l)
        {
            l--;
            ans=(ans*num[l])%1000000007;
            for(int j=0;j<cnt[l];j++)
            {
                int now=p[l][j];
                if(nowcnt[now]==0)
                {
                    ans=(ans*ni[now])%1000000007;
                    ans=(ans*(now-1))%1000000007;
                }
                nowcnt[now]++;
            }
        }
        que[i].ans=ans;
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct query
{
    int l;
    int r;
    int id;
    long long ans;
};
query que[200001];
int n;
int prime[1001],isprime[1001];
int num[200001];
int leftm[1000001];
long long ni[1000001];
long long c[200001];
bool cmp1(query a,query b)
{
    return a.l>b.l;
}
bool cmp2(query a,query b)
{
    return a.id<b.id;
}
int lowbit(int x)
{
    return x&-x;
}
void mul(int x,int y)
{
    while(x<=n)
    {
        c[x]=(c[x]*y)%1000000007;
        x=x+lowbit(x);
    }
}
long long sum(int x)
{
    long long ans=1;
    while(x>0)
    {
        ans=(ans*c[x])%1000000007;
        x=x-lowbit(x);
    }
    return ans;
}
long long quick_pow(long long x,long long y,int mod)
{
    long long z=1;
    while(y)
    {
        if(y%2)z=(z*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return z;
}
int main()
{
    int top=0;
    ni[1]=1;
    for(int i=2;i<=1000;i++)
    {
        if(isprime[i]==0)
        {
            prime[top++]=i;
            for(int j=i*i;j<=1000;j=j+i)
            {
                isprime[j]=1;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        ni[i]=quick_pow(i,1000000005,1000000007);
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
        c[i]=1;
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&que[i].l,&que[i].r);
        que[i].id=i;
    }
    sort(que,que+q,cmp1);
    int f=0;
    for(int i=n;i>=1;i--)
    {
        mul(i,num[i]);
        int a=num[i];
        for(int j=0;j<top&&prime[j]*prime[j]<=a;j++)
        {
            if(a%prime[j]==0)
            {
                int p=leftm[prime[j]];
                if(p)
                {
                    long long ph=prime[j];
                    ph=(ph*ni[prime[j]-1])%1000000007;
                    mul(p,ph);
                }
                leftm[prime[j]]=i;
                long long ph=prime[j]-1;
                ph=(ph*ni[prime[j]])%1000000007;
                mul(i,ph);
                while(a%prime[j]==0)a=a/prime[j];
            }
        }
        if(a!=1)
        {
            int p=leftm[a];
            if(p)
            {
                long long ph=a;
                ph=(ph*ni[a-1])%1000000007;
                mul(p,ph);
            }
            leftm[a]=i;
            long long ph=a-1;
            ph=(ph*ni[a])%1000000007;
            mul(i,ph);
        }
        while(f<q&&que[f].l==i)
        {
            que[f].ans=sum(que[f].r);
            f++;
        }
    }
    sort(que,que+q,cmp2);
    for(int i=0;i<q;i++)
    {
        printf("%I64d\n",que[i].ans);
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
const int md=1000000007;
int n,m,i,j,e,cur,a[200200],s[200200],k[200200],r[200200];
vector<pii> v[200200];
pii b[200200];
map<int,int> w;
map<int,int>::iterator it;
long long pw(int a, int b) {
  if (b==0) return 1LL;
  if (b&1) return (a*pw(a,b-1))%md;
  long long x=pw(a,b/2);
  return (x*x)%md;
}
void add(int i, long long v) {
  for (; i<=n; i=(i<<1)-(i&(i-1))) s[i]=(s[i]*v)%md;
}
int mul(int i) {
  long long r=1;
  for (; i>0; i&=i-1) r=(r*s[i])%md;
  return r;
}
void mno(int i, int j) {
  int c=((j-1)*pw(j,md-2))%md;
  if (w.count(j)) v[w[j]].push_back(make_pair(c,i)); else add(i,c);
  w[j]=i;
}
bool cmp(int i, int j) { return b[i]<b[j]; }
int main() {
  scanf("%d",&n);
  for (i=1; i<=n; i++) s[i]=1;
  for (i=1; i<=n; i++) {
    scanf("%d",&a[i]);
    add(i,cur=a[i]);
    for (j=2; j*j<=cur; j++) if (cur%j==0) {
      mno(i,j);
      for (; cur%j==0; cur/=j);
    }
    if (cur>1) mno(i,cur);
  }
  for (it=w.begin(); it!=w.end(); it++) v[it->second].push_back(make_pair(((it->first-1)*pw(it->first,md-2))%md,0));
  scanf("%d",&m);
  for (i=0; i<m; i++) {
    scanf("%d%d",&b[i].first,&b[i].second);
    k[i]=i;
  }
  sort(k,k+m,cmp);
  for (i=1, j=0; i<=n && j<m; i++) {
    for (; j<m && b[k[j]].first==i; j++) r[k[j]]=mul(b[k[j]].second);
    add(i,pw(a[i],md-2));
    for (e=0; e<v[i].size(); e++) {
      add(i,pw(v[i][e].first,md-2));
      if (v[i][e].second>0) add(v[i][e].second,v[i][e].first);
    }
  }
  for (i=0; i<m; i++) printf("%d\n",r[i]);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Rep(i,x,y) for (i=x;i<=y;++i)

const int Mod = 1000000007;
int n,i,x,Fac[1011110],B[1011101],A[1011101],Add[4011110],E[1011111],D[1011111][22],j,p[4011010],m,prime[1011001],Get[1111111],Late[1111111],tot;
struct Askpre {
    int l,r,x;
} Ask[1000101];

#define LL long long

bool cmp(Askpre x,Askpre y) {
    return x.r<y.r;
}

int Pow(int x,int y) {
    int t=1;
    while (y) {
        if (y&1) t=(LL)t*x%Mod;
        x=(LL)x*x%Mod;
        y>>=1;
    }
    return t;
}

void Pushdown(int x,int l,int r) {
    if (Add[x]!=1) {
        Add[x<<1]=(LL)Add[x<<1]*Add[x]%Mod;
        Add[x<<1|1]=(LL)Add[x<<1|1]*Add[x]%Mod;
        p[x<<1]=(LL)p[x<<1]*Add[x]%Mod;
        p[x<<1|1]=(LL)p[x<<1|1]*Add[x]%Mod;
        Add[x]=1;
    }
}

int Askp(int x,int y,int l,int r) {
    if (l==r) return p[x];
    int Mid=(l+r)>>1;
    Pushdown(x,l,r);
    if (y<=Mid) return Askp(x<<1,y,l,Mid);
    if (Mid+1<=y) return Askp(x<<1|1,y,Mid+1,r);
}

void Insert(int x,int y,int L,int R,int l,int r) {
    printf("%d %d\n",l,r);
    if (L<=l&&r<=R) {
        Add[x]=(LL)Add[x]*y%Mod;
        p[x]=(LL)p[x]*y%Mod;
        return;
    }
    int Mid=(l+r)>>1;
    Pushdown(x,l,r);
    if (L<=Mid) Insert(x<<1,y,L,R,l,Mid);
    if (Mid+1<=R) Insert(x<<1|1,y,L,R,Mid+1,r);
}

int main () {
    scanf("%d",&n);
    Rep(i,2,1000001) {
        if (!A[i]) prime[++tot]=i;
        Rep(j,1,tot) {
            if (i*prime[j]>1000000) break;
            A[i*prime[j]]=0;
            if (i%prime[j]==0) break;
        }
    }
    Rep(i,1,n) scanf("%d",&B[i]);
    Fac[0]=1;
    Rep(i,1,n) Fac[i]=(LL)Fac[i-1]*B[i]%Mod;
    Rep(i,1,n) {
        for (j=1;prime[j]*prime[j]<=B[i];++j) {
            if (B[i]%prime[j]==0) D[i][++E[i]]=prime[j];
            while (B[i]%prime[j]==0) B[i]=B[i]/prime[j];
        }
        if (B[i]>1) D[i][++E[i]]=B[i];
    }
    scanf("%d",&m);
    Rep(i,1,m) {  scanf("%d%d",&Ask[i].l,&Ask[i].r);  Ask[i].x=i;  }
    sort(Ask+1,Ask+m+1,cmp);
    Rep(i,1,(n<<1|1)) Add[i]=p[i]=1;  x=1;
    Rep(i,(n<<1),((n<<1)+(n<<1))) Add[i]=p[i]=1;
    Rep(i,1,n) {
        Rep(j,1,E[i]) {
            Insert(1,(LL)(D[i][j]-1)*Pow(D[i][j],Mod-2)%Mod,Late[D[i][j]]+1,i,1,n);
            Late[D[i][j]]=i;
        }
        while (x<=m&&Ask[x].r==i) {  Get[Ask[x].x]=Askp(1,Ask[x].l,1,n);  ++x;  }
    }
    Rep(i,1,m) Get[Ask[i].x]=(LL)Get[Ask[i].x]*Fac[Ask[i].r]%Mod*Pow(Fac[Ask[i].l-1],Mod-2)%Mod;
    Rep(i,1,m) printf("%d\n",Get[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Rep(i,x,y) for (i=x;i<=y;++i)

const int Mod = 1000000007;
int n,i,x,Fac[1011110],B[1011101],A[1011101],Add[4011110],E[1011111],D[1011111][22],j,p[4011010],m,prime[1011001],Get[1111111],Late[1111111],tot;
struct Askpre {
    int l,r,x;
} Ask[1000101];

#define LL long long

bool cmp(Askpre x,Askpre y) {
    return x.r<y.r;
}

int Pow(int x,int y) {
    int t=1;
    while (y) {
        if (y&1) t=(LL)t*x%Mod;
        x=(LL)x*x%Mod;
        y>>=1;
    }
    return t;
}

void Pushdown(int x,int l,int r) {
    if (Add[x]!=1) {
        Add[x<<1]=(LL)Add[x<<1]*Add[x]%Mod;
        Add[x<<1|1]=(LL)Add[x<<1|1]*Add[x]%Mod;
        p[x<<1]=(LL)p[x<<1]*Add[x]%Mod;
        p[x<<1|1]=(LL)p[x<<1|1]*Add[x]%Mod;
        Add[x]=1;
    }
}

int Askp(int x,int y,int l,int r) {
    if (l==r) return p[x];
    int Mid=(l+r)>>1;
    Pushdown(x,l,r);
    if (y<=Mid) return Askp(x<<1,y,l,Mid);
    if (Mid+1<=y) return Askp(x<<1|1,y,Mid+1,r);
}

void Insert(int x,int y,int L,int R,int l,int r) {
    //printf("%d %d\n",l,r);
    if (L<=l&&r<=R) {
        Add[x]=(LL)Add[x]*y%Mod;
        p[x]=(LL)p[x]*y%Mod;
        return;
    }
    int Mid=(l+r)>>1;
    Pushdown(x,l,r);
    if (L<=Mid) Insert(x<<1,y,L,R,l,Mid);
    if (Mid+1<=R) Insert(x<<1|1,y,L,R,Mid+1,r);
}

int main () {
    scanf("%d",&n);
    Rep(i,2,1000001) {
        if (!A[i]) prime[++tot]=i;
        Rep(j,1,tot) {
            if (i*prime[j]>1000000) break;
            A[i*prime[j]]=0;
            if (i%prime[j]==0) break;
        }
    }
    Rep(i,1,n) scanf("%d",&B[i]);
    Fac[0]=1;
    Rep(i,1,n) Fac[i]=(LL)Fac[i-1]*B[i]%Mod;
    Rep(i,1,n) {
        for (j=1;prime[j]*prime[j]<=B[i];++j) {
            if (B[i]%prime[j]==0) D[i][++E[i]]=prime[j];
            while (B[i]%prime[j]==0) B[i]=B[i]/prime[j];
        }
        if (B[i]>1) D[i][++E[i]]=B[i];
    }
    scanf("%d",&m);
    Rep(i,1,m) {  scanf("%d%d",&Ask[i].l,&Ask[i].r);  Ask[i].x=i;  }
    sort(Ask+1,Ask+m+1,cmp);
    Rep(i,1,(n<<1|1)) Add[i]=p[i]=1;  x=1;
    Rep(i,(n<<1),((n<<1)+(n<<1))) Add[i]=p[i]=1;
    Rep(i,1,n) {
        Rep(j,1,E[i]) {
            Insert(1,(LL)(D[i][j]-1)*Pow(D[i][j],Mod-2)%Mod,Late[D[i][j]]+1,i,1,n);
            Late[D[i][j]]=i;
        }
        while (x<=m&&Ask[x].r==i) {  Get[Ask[x].x]=Askp(1,Ask[x].l,1,n);  ++x;  }
    }
    Rep(i,1,m) Get[Ask[i].x]=(LL)Get[Ask[i].x]*Fac[Ask[i].r]%Mod*Pow(Fac[Ask[i].l-1],Mod-2)%Mod;
    Rep(i,1,m) printf("%d\n",Get[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*30],ls[maxn*30],rs[maxn*30],tot;
int s1[maxn*30],s2[maxn*30],s3[maxn*30];

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=tot++;
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3)
{
	x=tot++;
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3);
	}
	up(x);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2));
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*35],ls[maxn*35],rs[maxn*35],tot;
int s1[maxn*35],s2[maxn*35],s3[maxn*35];

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=tot++;
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3)
{
	x=tot++;
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3);
	}
	up(x);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2));
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*43],ls[maxn*43],rs[maxn*43],tot;
int s1[maxn*43],s2[maxn*43],s3[maxn*43];

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=tot++;
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3)
{
	x=tot++;
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3);
	}
	up(x);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2));
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*21],ls[maxn*21],rs[maxn*21],tot;
int s1[maxn*21],s2[maxn*21],s3[maxn*21];

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=tot++;
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3)
{
	x=tot++;
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3);
	}
	up(x);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2));
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*40],ls[maxn*40],rs[maxn*40],tot;
int s1[maxn*40],s2[maxn*40],s3[maxn*40];
int pool[maxn*40],ptop;

inline int getp()
{
	if(ptop)return pool[--ptop];
	return tot++;
}

inline void collect(int x)
{
	pool[ptop++]=x;
}

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=getp();
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3,int rr)
{
	x=getp();
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		if(fa!=rr)collect(fa);
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3,ls[rr]);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3,rs[rr]);
	}
	up(x);
	if(fa!=rr)collect(fa);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		LL v1=1,v2=1,v3=1;
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2),rt[i-1]);
			}
			f[k]=i;
			v1=v1*tmp%mod;
			v2=v2*quipow(k,mod-2)%mod;
			v3=v3*(k-1)%mod;
		}
		upd(rt[i],1,n,rt[i],i,v1,v2,v3,rt[i-1]);
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*35],ls[maxn*35],rs[maxn*35],tot;
int s1[maxn*35],s2[maxn*35],s3[maxn*35];
int pool[maxn*35],ptop;

inline int getp()
{
	if(ptop)return pool[--ptop];
	return tot++;
}

inline void collect(int x)
{
	pool[ptop++]=x;
}

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=getp();
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3,int rr)
{
	x=getp();
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		if(fa!=rr)collect(fa);
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3,ls[rr]);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3,rs[rr]);
	}
	up(x);
	if(fa!=rr)collect(fa);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2),rt[i-1]);
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1,rt[i-1]);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define pb push_back
#define mod 1000000007
const int maxn=200010;
const int maxa=1000010;
int n,m,a[maxn];

int prm[maxa],ptot;
int b[maxa],f[maxa];
bool vis[maxa];

inline LL quipow(LL x,LL k)
{
	LL ret=1;
	while(k)
	{
		if(k&1)ret=ret*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ret;
}

void init(int mx)
{
	for(int i=2;i<=mx;i++)
	{
		if(!vis[i])
		{
			prm[++ptot]=i;
			b[i]=i;
		}
		for(int j=1;j<=ptot&&(LL)i*prm[j]<=mx;j++)
		{
			vis[i*prm[j]]=1;
			b[i*prm[j]]=prm[j];
			if(i%prm[j]==0)break;
		}
	}
}

int rt[maxn*35],ls[maxn*35],rs[maxn*35],tot;
int s1[maxn*35],s2[maxn*35],s3[maxn*35];
int pool[maxn*35],ptop;

inline int getp()
{
	if(ptop)return pool[--ptop];
	return tot++;
}

inline void collect(int x)
{
	pool[ptop++]=x;
}

inline void up(int x)
{
	s1[x]=s1[ls[x]]*1ll*s1[rs[x]]%mod;
	s2[x]=s2[ls[x]]*1ll*s2[rs[x]]%mod;
	s3[x]=s3[ls[x]]*1ll*s3[rs[x]]%mod;
}

void build(int &x,int l,int r)
{
	x=getp();
	s1[x]=s2[x]=s3[x]=1;
	if(l==r)return;
	int mid=l+r>>1;
	build(ls[x],l,mid);
	build(rs[x],mid+1,r);
}

void upd(int &x,int l,int r,int fa,int pos,LL v1,LL v2,LL v3,int rr)
{
	x=getp();
	if(fa!=rr)collect(fa);
	if(l==r)
	{
		s1[x]=s1[fa]*v1%mod;
		s2[x]=s2[fa]*v2%mod;
		s3[x]=s3[fa]*v3%mod;
		return;
	}
	int mid=l+r>>1;
	if(pos<=mid)
	{
		rs[x]=rs[fa];
		upd(ls[x],l,mid,ls[fa],pos,v1,v2,v3,ls[rr]);
	}
	else
	{
		ls[x]=ls[fa];
		upd(rs[x],mid+1,r,rs[fa],pos,v1,v2,v3,rs[rr]);
	}
	up(x);
}

LL qry(int x,int l,int r,int L,int R)
{
	if(L<=l && r<=R)
	{
		return s1[x]*1ll*s2[x]%mod *s3[x]%mod;
	}
	int mid=l+r>>1;
	LL ret=1;
	if(L<=mid)ret=qry(ls[x],l,mid,L,R);
	if(mid<R)ret=ret*qry(rs[x],mid+1,r,L,R)%mod;
	return ret;
}

int main()
{
	scanf("%d",&n);
	int mxa=0;
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		mxa=max(mxa,a[i]);
	}
	init(mxa);
	build(rt[0],1,n);
	rep(i,1,n)
	{
		rt[i]=rt[i-1];
		while(a[i]>1)
		{
			int k=b[a[i]];
			LL tmp=1;
			while(a[i]%k==0)
			{
				tmp=tmp*k%mod;
				a[i]/=k;
			}
			if(f[k])
			{
				upd(rt[i],1,n,rt[i],f[k],1,k,quipow(k-1,mod-2),rt[i-1]);
			}
			f[k]=i;
			upd(rt[i],1,n,rt[i],i,tmp,quipow(k,mod-2),k-1,rt[i-1]);
		}
	}

	scanf("%d",&m);
	rep(i,1,m)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=qry(rt[r],1,n,l,r);
		printf("%d\n",ans);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 200000 + 10;
const int MOD = 1e9 + 7;

typedef pair<int, int> ii;

vector<ii> qu[MAX_N];
int n, q, a[MAX_N], last[1000000 + 10], ans[MAX_N];
int c[MAX_N], fac[MAX_N];

void add(int p, int d) {
    if(p == 0)
        return ;
    while(p <= n) {
        c[p] = 1LL * c[p] * d % MOD;
        p += p & -p;
    }
}

int ask(int p) {
    int ret = 1;
    while(p > 0) {
        ret = 1LL * ret * c[p] % MOD;
        p -= p & -p;
    }
    return ret;
}

int pow(int a, int b) {
    int ret = 1;
    while(b) {
        if(b & 1)
            ret = 1LL * ret * a % MOD;
        a = 1LL * a * a % MOD; b >>= 1;
    }
    return ret;
}

int inv(int x) {
    return pow(x, MOD - 2);
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        c[i] = 1;
    fac[0] = 1;
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        fac[i] = 1LL * fac[i - 1] * a[i] % MOD;
    }
    scanf("%d", &q);
    for(int i = 1; i <= q; i++) {
        int l, r; scanf("%d%d", &l, &r);
        qu[r].push_back(ii(l, i));
    }
    for(int i = 1; i <= n; i++) {
        int x = a[i];
        for(int j = 2; 1LL * j * j <= x; j++)
            if(x % j == 0) {
                while(x % j == 0)
                    x /= j;
                add(i, 1LL * (j - 1) * inv(j) % MOD);
                add(last[j], inv(1LL * (j - 1) * inv(j) % MOD));
                last[j] = i;
            }
        if(x > 1) {
            add(i, 1LL * (x - 1) * inv(x) % MOD);
            add(last[x], inv(1LL * (x - 1) * inv(x) % MOD));
            last[x]= i;
        }
        for(int j = 0; j < qu[i].size(); j++) {
            int k = qu[i][j].first;
            ans[qu[i][j].second] = 1LL * fac[i] * inv(fac[k - 1]) % MOD * ask(i) % MOD * inv(ask(k - 1)) % MOD;
        }
    }
    for(int i = 1; i <= q; i++)
        printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define fi first
#define mod 1000000007LL
#define se second
#define maxn 200005
#define pb push_back
#define pii pair < int ,int>
#define mp make_pair
using namespace std;
int pre[maxn],n,m,i,j,k,d[maxn],a,b,c,pos[1000005],tree[4*maxn],son,ans[maxn];
bool gez[1000005];
pair < pii ,int > q[maxn];
vector < int > bol[1000005];
vector < pii > e[maxn];
int fe(int x,int y){
	if(!y)
	return 1;
	int a=fe(x,y/2);
	a=(1LL*a*a)%mod;
	if(y%2)
	a=(1LL*a*x)%mod;
	return a;
}
int query(int nd,int bas,int son,int l,int r){
	if(l>son or r<bas)
	return 1;
	if(bas>=l and son<=r)
	return tree[nd];
	int orta=(bas+son)/2;
	int val=(1LL*query(2*nd,bas,orta,l,r)*query(2*nd+1,orta+1,son,l,r))%mod;
	return val;
}
void update(int nd,int bas,int son,int l,int val){
	 if(l>son or l<bas)
	 return ;
	 if(bas==son){
		tree[nd]=(1LL*tree[nd]*val)%mod;
		return ;
	 }
	 int orta=(bas+son)/2;
	 update(2*nd,bas,orta,l,val);
	 update(2*nd+1,orta+1,son,l,val);
	 tree[nd]=(1LL*tree[2*nd]*tree[2*nd+1])%mod;
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	scanf("%d",&d[i]);
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		q[i]=mp(mp(a,b),i);
	}
	sort(q+1,q+m+1);
	pre[0]=1;
	for(i=1;i<=n;i++)
	pre[i]=(1LL*d[i]*pre[i-1])%mod;
	for(i=2;i<=1000;i++){
		if(gez[i])
		continue;
		for(j=i*i;j<=1e6;j+=i){
			bol[j].pb(i);
			gez[j]=true;
		}
	}
	for(i=n;i;i--){
	    int val=d[i];
	    for(j=0;j<bol[d[i]].size();j++){
			while(val%bol[d[i]][j]==0)
			val/=bol[d[i]][j];
		}
		if(val>1)
		bol[d[i]].pb(val);
		for(j=0;j<bol[d[i]].size();j++){
		e[i].pb(mp(bol[d[i]][j],pos[bol[d[i]][j]]));
		pos[bol[d[i]][j]]=i;
	    }
	}
	for(i=1;i<=4*n+10;i++)
	tree[i]=1;
	for(i=2;i<=1e6;i++)
	if(!gez[i] and pos[i]){
		int val=(1LL*fe(i,mod-2)*(i-1))%mod;
	update(1,1,n,pos[i],val);
    }
	son=1;
	for(i=1;i<=m;i++){
		for(;son<q[i].fi.fi;son++)
	    for(j=0;j<e[son].size();j++){
			int val2=(1LL*fe(e[son][j].fi,mod-2)*(e[son][j].fi-1))%mod;
	    update(1,1,n,e[son][j].se,val2);
	    }
		int val=1,l,r;
		r=q[i].fi.se;
		l=q[i].fi.fi;
		val=(1LL*val*pre[r]*fe(pre[l-1],mod-2))%mod;
		val=(1LL*val*query(1,1,n,l,r))%mod;
		ans[q[i].se]=val;
	}
	for(i=1;i<=m;i++)
	printf("%d\n",ans[i]);
	return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
using namespace std;

typedef pair<int, int> pii;
const int MAXN = 2000000 + 10;
const int MAXV = 1000000 + 100;
const int MOD = 1e9 + 7;

vector<pii> ask[MAXN];
int n;
int a[MAXN], pre[MAXV];
int c[MAXN], fac[MAXN];
int ans[MAXN];

int pow_mod(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return pow_mod(x, MOD - 2);
}

inline int lowbit(int x){
    return x & -x;
}

void add(int x, int d) {
    if(!x){
        return ;
    }
    while(x <= n) {
        c[x] = 1LL * c[x] * d % MOD;
        x += lowbit(x);
    }
}

int query(int x) {
    int res = 1;
    while(x > 0) {
        res = 1LL * res * c[x] % MOD;
        x -= lowbit(x);
    }
    return res;
}

int main(int argc, char const *argv[]){
    //ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++){
        c[i] = 1;
    }
    fac[0] = 1;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        fac[i] = 1LL * fac[i - 1] * a[i] % MOD;
    }
    int q;
    scanf("%d", &q);
    for(int i = 1; i <= q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        ask[r].push_back(pii(l, i));
    }
    for(int i = 1; i <= n; i++) {
        int tmp = a[i];
        for(int j = 2; j * j <= tmp; j++)
            if(!(tmp % j)) {
                do{
                    tmp /= j;
                }while(!(tmp % j));
                add(i, 1LL * (j - 1) * inv(j) % MOD);
                add(pre[j], inv(1LL * (j - 1) * inv(j) % MOD));
                pre[j] = i;
            }
        if(tmp != 1) {
            add(i, 1LL * (tmp - 1) * inv(tmp) % MOD);
            add(pre[tmp], inv(1LL * (tmp - 1) * inv(tmp) % MOD));
            pre[tmp]= i;
        }
        for(int j = 0; j < ask[i].size(); j++) {
            int t = ask[i][j].fi;
            ans[ask[i][j].se] = (((1LL * fac[i] * inv(fac[t- 1]) % MOD) * query(i) % MOD) * inv(query(t - 1))) % MOD;
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
using namespace std;

typedef pair<int, int> pii;
const int MAXN = 2000000 + 10;
const int MAXV = 1000000 + 100;
const int MOD = 1e9 + 7;

vector<pii> ask[MAXN];
int n;
int a[MAXN], pre[MAXV];
int c[MAXN], fac[MAXN];
int ans[MAXN];

int pow_mod(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return pow_mod(x, MOD - 2);
}

inline int lowbit(int x){
    return x & -x;
}

void add(int x, int d) {
    if(!x){
        return ;
    }
    while(x <= n) {
        c[x] = 1LL * c[x] * d % MOD;
        x += lowbit(x);
    }
}

int query(int x) {
    int res = 1;
    while(x > 0) {
        res = 1LL * res * c[x] % MOD;
        x -= lowbit(x);
    }
    return res;
}

int main(int argc, char const *argv[]){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++){
        c[i] = 1;
    }
    fac[0] = 1;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        fac[i] = 1LL * fac[i - 1] * a[i] % MOD;
    }
    int q;
    scanf("%d", &q);
    for(int i = 1; i <= q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        ask[r].push_back(pii(l, i));
    }
    for(int i = 1; i <= n; i++) {
        int tmp = a[i];
        for(int j = 2; j * j <= tmp; j++)
            if(!(tmp % j)) {
                do{
                    tmp /= j;
                }while(!(tmp % j));
                add(i, 1LL * (j - 1) * inv(j) % MOD);
                add(pre[j], inv(1LL * (j - 1) * inv(j) % MOD));
                pre[j] = i;
            }
        if(tmp != 1) {
            add(i, 1LL * (tmp - 1) * inv(tmp) % MOD);
            add(pre[tmp], inv(1LL * (tmp - 1) * inv(tmp) % MOD));
            pre[tmp]= i;
        }
        for(int j = 0; j < ask[i].size(); j++) {
            int t = ask[i][j].fi;
            ans[ask[i][j].se] = (((1LL * fac[i] * inv(fac[t- 1]) % MOD) * query(i) % MOD) * inv(query(t - 1))) % MOD;
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}