#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define ll long long
using namespace std;
const int maxn=100007,mo=1000000007;
int i,j,k,l,t,n,m,kuai,r;
ll ans1,ans[maxn],T[maxn];
int c[maxn],ni[maxn],shu[maxn];
struct node{
int a,b,c,d,e;
}a[maxn];
bool cmp(node x,node y){
return x.d<y.d||x.d==y.d&&x.e<y.e;
}
ll qsm(ll x,ll y){
ll z=1;
if(y==0)return 0;
while(y!=0){
if(y&1)z=z*x%mo;
x=x*x%mo;
y/=2;
}
return z;
}
void update(int x,int y,int z){
int i;
fo(i,x,y){
if(z==-1){
ans1=(ans1-T[c[i]]+mo)%mo;
shu[c[i]]--;
if(!shu[c[i]]){T[c[i]]=0;continue;}
T[c[i]]=T[c[i]]*ni[c[i]]%mo;
ans1=(ans1+T[c[i]])%mo;
}else{
ans1=(ans1-T[c[i]]+mo)%mo;
shu[c[i]]++;
if(shu[c[i]]==1)T[c[i]]=c[i];
else T[c[i]]=T[c[i]]*c[i]%mo;
ans1=(ans1+T[c[i]])%mo;
}
}
}
int main(){
scanf("%d%d",&n,&m);
fo(i,1,n){
scanf("%d",&c[i]);
ni[c[i]]=qsm(c[i],mo-2);
}
kuai=sqrt(n);
fo(i,1,m){
scanf("%d%d",&a[i].a,&a[i].b);
a[i].c=i;
a[i].d=a[i].a/kuai+1;
a[i].e=a[i].b/kuai+1;
}
sort(a+1,a+1+m,cmp);
l=1;r=0;
fo(i,1,m){
k=a[i].a;t=a[i].b;
if(k>l)update(l,k-1,-1);
else if(k<l)update(k,l-1,1);
if(r>t)update(t+1,r,-1);
else if(r<t)update(r+1,t,1);
l=k;r=t;
ans[a[i].c]=(ans1+mo)%mo;
}
fo(i,1,m)printf("%lld\n",ans[i]);
}