#include<bits/stdc++.h>
using namespace std;
int n,t,m,q;
int a[250050],b[250050];
struct data{
	int z,w;
	data(){z=w=0;}
	data(int _z,int _w){z=_z,w=_w;}
};
data tree[250050*4],tree2[250050*4];
bool operator <(data a1,data a2){
	return a1.z<a2.z;
}
data max(data a1,data a2){
	if(a2<a1)return a1;
	return a2;
}
void mt(int a,int l,int r){
//	cout<<a<<" "<<l<<" "<<r<<endl;
//	Sleep(100)
	if(l==r){
		tree[a]=data(::a[l],l);
		return;
	}
	mt(a*2,l,(l+r)/2);
	mt(a*2+1,(l+r)/2+1,r);
	tree[a]=max(tree[a*2],tree[a*2+1]);
	return;
}
void mt2(int a,int l,int r){
	if(l==r){
		tree2[a]=data(b[l],l);
		return;
	}
	mt2(a*2,l,(l+r)/2);
	mt2(a*2+1,(l+r)/2+1,r);
	tree2[a]=max(tree2[a*2],tree2[a*2+1]);
	return;
}
data find1(int root,int l,int r,int L,int R){
	if(l>=L&&r<=R)return tree[root];
	if(r<L||l>R)return data();
	return max(find1(root*2,l,(l+r)/2,L,R),find1(root*2+1,(l+r)/2+1,r,L,R));
}
data find2(int root,int l,int r,int L,int R){
	if(l>=L&&r<=R)return tree2[root];
	if(r<L||l>R)return data();
	return max(find2(root*2,l,(l+r)/2,L,R),find2(root*2+1,(l+r)/2+1,r,L,R));
}
unsigned long long find(int l,int r){
	if(l>r)return 0;
	if(l==r)return a[l]*1ull*b[r];
	data a1=find1(1,1,n,l,r),a2=find2(1,1,n,l,r);
	int ll=min(a1.w,a2.w),rr=max(a1.w,a2.w);
//	cout<<l<<" "<<r<<" "<<ll<<" "<<rr<<endl;
	return find(l,rr-1)+find(ll+1,r)-find(ll+1,rr-1)+a1.z*1ull*a2.z*1ull*(r-rr+1)*1ull*(ll-l+1);
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
//	cout<<n<<endl;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	mt(1,1,n);
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	mt2(1,1,n);
//	cout<<tree2[1].w<<" "<<tree2[1].z<<endl;
	cin>>q;
	for(int i=1,l,r;i<=q;i++){
		scanf("%d%d",&l,&r);
		printf("%lld\n",find(l,r));
//		if(i==5)break;
	}
	return 0;
}