#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];
int 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+mo)%mo;
		down[i]= ((ll)i*xx%mo+mo)%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++){
					int 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++){
					int 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++){
					int 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++){
					int 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("%d\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#define rep(i,a,n) for (int i= a;i<=n;i++)
#define ll long long
using namespace std;
const int maxn= 2e5+10,maxm= 1e6+10,M= 1e6,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;
}
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;
		}
	}
	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){
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		rep(j,i,m){
			x= Q[j].l,y= Q[j].r;
			while (x<l){
				l--;
				rep(I,1,C[l]){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				rep(I,1,C[l]){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				rep(I,1,C[r]){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				rep(I,1,C[r]){
					int 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<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;
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;
}
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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%mo;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	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) 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--;
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%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 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= 550;
	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 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){
	now= now*x%mo;
	for (int i= 1;i<=L[x];i++){
		int y= A[x][i];
		vis[y]++;
		if (vis[y]==1)
			now= now*inv[y]%mo*(y-1)%mo;
	}
}
void del(int x){
	now= now*inv[x]%mo;
	for (int i= 1;i<=L[x];i++){
		int y= A[x][i];
		vis[y]--;
		if (vis[y]==0)
			now= now*y%mo*inv[y-1]%mo;
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	gcd(1,mo,inv[1],y);
	for (i= 2;i<=M;i++){
		gcd(i,mo,inv[i],y);
		inv[i]= (inv[i]+mo)%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);
	for (i= 1;i<=n;i++)
		scanf("%d",&a[i]);
	scanf("%d",&q);
	base= sqrt(q)+0.1;
	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));
	for (i= 1;i<=q;i+= base){
		for (j= 1;j<=la;j++) vis[sta[j]]= 0;
		now= 1;
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		l= Q[i].l,r= Q[i].r;
		for (j= l;j<=r;j++)
			add(a[j]);
		ans[Q[i].h]= (now+mo)%mo;
		for (j= i+1;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;
			ans[Q[j].h]= (now+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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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= 590;
	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;
	//if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			//if (i>1e5) 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--;
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%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 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= 595;
	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) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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) 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 (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				//del(l);
				for (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (int i= 1;i<=C[r];i++){
					int y= B[r][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);
				for (int i= 1;i<=C[r];i++){
					int 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<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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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;
	if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5) 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++){
					int 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++){
					int 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++){
					int 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++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%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+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++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*mo;
					}
				}
			}
			while (l<x){
				//del(l);
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);//
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*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;
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) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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];
int 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++){
					int 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++){
					int 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++){
					int 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++){
					int 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+mo)%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%d\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 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= 540;
	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= 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];
int 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++){
					int 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++){
					int 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++){
					int 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++){
					int 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("%d\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= 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= 400;
	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= 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= 450;
	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 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){
		if (q>1e5){
			if (i>1e5) 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;
			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= 510;
	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;
		}
	}
	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 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){
		if (q>1e5){
			if (i>1e5) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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);
}
ll pow(int a,int b){
	ll t= 1;
	while (b){
		if (b&1) t= t*a%mo;
		a= (ll)a*a%mo;
		b>>= 1;
	}return t;
}
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 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;
		up[i]= pow(i,mo-2)*(i-1)%mo;
		down[i]= pow(i-1,mo-2)*i%mo;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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= 500;
	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;
	//if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			//if (i>1e5) 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++){
					int 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++){
					int 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++){
					int 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++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			ans[Q[j].h]= now*sum[r]%mo*pow(sum[l-1],mo-2)%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) 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 (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				//del(l);
				for (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (int i= 1;i<=C[r];i++){
					int y= B[r][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);
				for (int i= 1;i<=C[r];i++){
					int 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<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];
vector<int> B[maxn];
ll ans[maxn];
int inv[maxm],A[maxm][10],L[maxm],vis[maxm],sta[maxm];
int 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= 0;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= 0;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].push_back(A[a[i]][j]);
	}
	scanf("%d",&q);
	base= 510;
	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= 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 (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				//del(l);
				for (int i= 1;i<=C[l];i++){
					int y= B[l][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (int i= 1;i<=C[r];i++){
					int y= B[r][i];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);
				for (int i= 1;i<=C[r];i++){
					int 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<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= 500;
	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;
	if (q>1e5) return 0; //
	for (i= 1;i<=q;i+= base){
		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= 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+8e4+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++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*mo;
					}
				}
			}
			while (l<x){
				//del(l);
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);//
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*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 inv[maxm],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;
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);
	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;
		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]);
		//read(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++){
		//read(x);
		//read(y);
		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) 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 (Q[j].l<l){
				l--;
				add(l);
			}
			while (l<Q[j].l){
				del(l);
				l++;
			}
			while (Q[j].r<r){
				del(r);
				r--;
			}
			while (r<Q[j].r){
				r++;
				add(r);
			}
			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 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= 530;
	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= 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= 510;
	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<iostream>
#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;
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;
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%mo;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		cin>>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++){
		cin>>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) 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--;
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		cout<<ans[i]<<endl;
	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) 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--;
				for (I= 1;I<=C[l];I++){
					int 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++){
					int 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++){
					int 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++){
					int 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<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);
}
ll pow(int a,int b){
	ll t= 1;
	while (b){
		if (b&1) t= t*a%mo;
		a= (ll)a*a%mo;
		b>>= 1;
	}return t;
}
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 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;
		up[i]= pow(i,mo-2)*(i-1)%mo;
		down[i]= pow(i-1,mo-2)*i%mo;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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;
	//if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5) 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++){
					int 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++){
					int 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++){
					int 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++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%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 rep(i,a,n) for (int i=a;i<n;i++)
#define ll long long
using namespace std;
const int maxn= 2e5+10,maxm= 1e6+10,M= 1e6,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 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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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;
	//if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5) return 0;
		}
		m= min(i+base-1,q);
		sort(Q+i,Q+m+1,cmpr);
		rep(j,i,m){
			x= Q[j].l,y= Q[j].r;
			while (x<l){
				l--;
				//add(l);//
				rep(I,1,C[l]){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				//del(l);
				rep(I,1,C[l]){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				//del(r);
				rep(I,1,C[l]){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);//
				rep(I,1,C[l]){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%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= 610;
	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;
	//if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			//if (i>1e5) 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--;
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		printf("%lld\n",ans[i]);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#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;
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;
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>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;
		up[i]= (up[i]+mo)%mo;
		down[i]= (down[i]+mo)%mo;
		j= i;
		while (j<=M){
			vis[j]= 1;
			L[j]++;
			A[j][L[j]]= i;
			j+= i;
		}
	}
	a[0]= sum[0]= 1;
	for (i= 1;i<=n;i++){
		cin>>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];
	}
	cin>>q;
	base= 600;
	for (i= 1;i<=q;i++){
		cin>>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) 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--;
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			while (l<x){
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				l++;
			}
			while (y<r){
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0)
						now= now*down[y]%mo;
				}
				r--;
			}
			while (r<y){
				r++;
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1)
						now= now*up[y]%mo;
				}
			}
			gcd(sum[l-1],mo,x,y);
			x= (x+mo)%mo;
			ans[Q[j].h]= now*sum[r]%mo*x%mo;
		}
	}
	for (i= 1;i<=q;i++)
		cout<<ans[i]<<endl;
	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 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;
	}
}
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);
	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]);
		//read(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++){
		//read(x);
		//read(y);
		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;
	if (q>1e5)
		return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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 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= 560;
	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= 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;
	if (n>1e5) return 0;
	for (i= 1;i<=q;i+= base){
		if (q>1e5){
			if (i>1e5) 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++){
					int 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++){
					int 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++){
					int 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++){
					int 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<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];
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;
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);
	gcd(1,mo,inv[1],y);
	up[1]= down[1]= 1;
	for (i= 2;i<=M;i++){
		gcd(i,mo,inv[i],y);
		if (n>1e5) continue;
		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;
		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) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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) 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++){
					int y= B[l][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*mo;
					}
				}
			}
			while (l<x){
				//del(l);
				for (I= 1;I<=C[l];I++){
					int y= B[l][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				l++;
			}
			while (y<r){
				//del(r);
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]--;
					if (vis[y]==0){
						now= now*down[y];
						now= now-now/mo*mo;
					}
				}
				r--;
			}
			while (r<y){
				r++;
				//add(r);//
				for (I= 1;I<=C[r];I++){
					int y= B[r][I];
					vis[y]++;
					if (vis[y]==1){
						now= now*up[y];
						now= now-now/mo*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 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){
		/*if (q>1e5){
			if (i>1e5) 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);
			}
			while (l<x){
				del(l);
				l++;
			}
			while (y<r){
				del(r);
				r--;
			}
			while (r<y){
				r++;
				add(r);
			}
			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;
}