#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N(250500);
int T,n;
ll a[N],b[N];
ll la[N],ra[N],lb[N],rb[N];
int sta[17][N],stb[17][N];
int aska(int l,int r){
	int res=0,now=l;
	for(int i=17;i>=0;--i){
		if(now+(1<<i)-1<=r){
			res=max(res,sta[i][now]);
			now+=(1<<i);
		}
	}
	return res;
}
int askb(int l,int r){
	int res=0,now=l;
	for(int i=17;i>=0;--i){
		if(now+(1<<i)-1<=r){
			res=max(res,stb[i][now]);
			now+=(1<<i);
		}
	}
	return res;
}
void init(){
	for(int i=1;i<=17;++i){
		for(int j=1;j+(1<<i)-1<=n;++j){
			sta[i][j]=max(sta[i-1][j],sta[i-1][j+(1<<(i-1))]);
			stb[i][j]=max(stb[i-1][j],stb[i-1][j+(1<<(i-1))]);
		}
	}
	int L,R,mid,res;int sd;
	for(int i=1;i<=n;++i){
		L=1,R=i;res=i;
		while(L<=R){
			mid=(L+R)>>1;
			if(aska(mid,i)<=a[i]) {res=mid;R=mid-1;}
			else L=mid+1;
		}
		la[i]=res;
		L=i,R=n;res=i;
		while(L<=R){
			mid=(L+R)>>1;
			if(aska(i,mid)<=a[i]) {res=mid;L=mid+1;}
			else R=mid-1;
		}
		ra[i]=res;
	}
	for(int i=1;i<=n;++i){
		L=1,R=i;res=i;
		while(L<=R){
			mid=(L+R)>>1;
			if(askb(mid,i)<=b[i]) {res=mid;R=mid-1;}
			else L=mid+1;
		}
		lb[i]=res;
		L=i,R=n;res=i;
		while(L<=R){
			mid=(L+R)>>1;
			if(askb(i,mid)<=b[i]) {res=mid;L=mid+1;}
			else R=mid-1;
		}
		rb[i]=res;
	}
}
ll res;
ll calc(ll L,ll R,ll mid){
	res=0;
	int gl,gr;
	for(ll i=L;i<=R;++i){
		if(rb[i]<mid||lb[i]>mid) continue;
		gl=max(lb[i],L),gr=min(rb[i],R);
		res+=(gr-max(i,mid)+1)*(min(i,mid)-gl+1)*b[i];
	}
	return res;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>T>>n;
	for(int i=1;i<=n;++i) cin>>a[i],sta[0][i]=a[i];
	for(int i=1;i<=n;++i) cin>>b[i],stb[0][i]=b[i];
	init();
	int Q;cin>>Q;
	ll x,y,L,R;ll ans;
	while(Q--){
		cin>>x>>y;ans=0;
		for(ll i=x;i<=y;++i){
			L=max(la[i],x),R=min(ra[i],y);
			ans+=a[i]*calc(L,R,i);
//			cout<<L<<' '<<R<<' '<<a[i]<<" "<<calc(L,R,i)<<endl;
		}
		cout<<ans<<endl;
	}
}