#include<bits/stdc++.h>
#define ci const int&
#define ull unsigned long long
using namespace std;
const int N=2.5e5+10;
int T,n,Q,a[N],b[N],lm,lg[N],mx[20][N],mi[20][N],L,R;
int al[N],pl[N],sl,ar[N],pr[N],sr,nl,nr;
ull ans,ta;
int Max(ci l,ci r){
	int k=lg[r-l+1];
	return mx[k][l]>mx[k][r-(1<<k)+1]?mi[k][l]:mi[k][r-(1<<k)+1];
}
void Solve(ci l,ci r){
	if(l>r)return;
	int mid=Max(l,r);
	Solve(l,mid-1),Solve(mid+1,r);
	//cout<<"SOLVE "<<l<<" "<<r<<",mid="<<mid<<"\n";
	sl=sr=0,al[0]=ar[0]=b[mid],pl[0]=pr[0]=mid;
	for(int i=mid-1;i>=l;--i)if(b[i]>al[sl])al[++sl]=b[i],pl[sl]=i;
	for(int i=mid+1;i<=r;++i)if(b[i]>ar[sr])ar[++sr]=b[i],pr[sr]=i;
	pl[sl+1]=l-1,pr[sr+1]=r+1;
	nl=nr=0,ta=1ull*(mid-pl[1])*(pr[1]-mid)*b[mid];
	while(nl<sl||nr<sr){
		if(nl<sl&&(nr==sr||al[nl+1]<ar[nr+1])){
			++nl;
			ta+=1ull*(pl[nl]-pl[nl+1])*(pr[nr+1]-mid)*al[nl];
		}else{
			++nr;
			ta+=1ull*(pr[nr+1]-pr[nr])*(mid-pl[nl+1])*ar[nr];
		}
	}
	//cout<<"TA="<<ta<<"\n";
	ans+=ta*a[mid];
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	while((1<<lm+1)<=n)++lm;
	for(int i=2;i<=N;++i)lg[i]=lg[i>>1]+1;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),mx[0][i]=a[i],mi[0][i]=i;
	for(int i=1;i<=n;++i)scanf("%d",&b[i]);
	for(int i=1;i<=lm;++i)for(int j=1;j+(1<<i)-1<=n;++j){
		mx[i][j]=max(mx[i-1][j],mx[i-1][j+(1<<i-1)]);
		if(mx[i][j]==mx[i-1][j])mi[i][j]=mi[i-1][j];
		else mi[i][j]=mi[i-1][j+(1<<i-1)];
	}
	scanf("%d",&Q);
	while(Q--)scanf("%d%d",&L,&R),ans=0,Solve(L,R),printf("%llu\n",ans);
	return 0;
}
