#include<bits/stdc++.h>
using namespace std;
#define ll __int128
template<typename T>inline void read(T &x){
	x=0;int f=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}
void put(ll x){
	if(x==0){putchar('0');return;}
	if(x<0){putchar('-');x=-x;}
	char ch[55];int tot;
	while(x){ch[++tot]=x%10+48;x/=10;}
	while(tot){putchar(ch[tot]),--tot;}
	return ;
}
const ll mod=(ll)1<<64;
int n,m,Size,block[200005];
int a[200005],b[200005];
ll ans[200005],ret;
struct node{
	int l,r,id;
	node(){
		l=r=id=0;
	}
	node(int x,int y,int z){
		l=x;r=y;id=z;
	}
	bool operator<(const node &y){
		return block[l]==block[y.l]?r<y.r:l<y.l;
	}
}e[200005];
inline void work(int x,int val,int l,int r,bool opt){
	int maxa=0,maxb=0;
	if(!opt)
		for(int i=l;i<=r;i++){
			maxa=max(maxa,a[i]);
			maxb=max(maxb,b[i]);
			ret=((ret+1ll*val*maxa*maxb%mod)%mod+mod)%mod;
		}
	else
		for(int i=r;i>=l;i--){
			maxa=max(maxa,a[i]);
			maxb=max(maxb,b[i]);
			ret=((ret+1ll*val*maxa*maxb%mod)%mod+mod)%mod;
		}
	return;
}
signed main(){
//	return system("fc match.out match3.ans"),0;
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(n);read(n);Size=sqrt(n)+1;
	for(int i=1;i<=n;i++)read(a[i]),block[i]=i/Size;
	for(int i=1;i<=n;i++)read(b[i]);
	read(m);
	for(int i=1,l,r;i<=m;i++) read(l),read(r),e[i]=node(l,r,i);
	sort(e+1,e+1+m);
	for(int i=1,l=0,r=0;i<=m;i++){
		for(;r<e[i].r;++r) work(r+1,1,l,r+1,1);
		for(;l>e[i].l;--l) work(l-1,1,l-1,r,0);
		for(;r>e[i].r;--r) work(r,-1,l,r,1);
		for(;l<e[i].l;++l) work(l,-1,l,r,0);
		ans[e[i].id]=ret;
	}
	for(int i=1;i<=m;i++)put(ans[i]),putchar('\n');
	return 0;
}

