#include<bits/stdc++.h>
#define ull unsigned long long
#define int unsigned long long
using namespace std;
const int N=3e5+110;
int read(){
	int x=0,f=1;char c=getchar();
	while(c>'9' || c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return x*f;
}
ull a[N],b[N];
int T,n,la[N],ra[N],lb[N],rb[N];
int st[N],top,q;
void pre(){
	top=0;
	for(int i=1;i<=n;i++){
		while(top && a[st[top]]<a[i])top--;
		if(top)la[i]=st[top];
		else la[i]=0;
		st[++top]=i;
	}
	top=0;
	for(int i=n;i>=1;i--){
		while(top && a[st[top]]<a[i])top--;
		if(top)ra[i]=st[top];
		else ra[i]=n+1;
		st[++top]=i;
	}
	top=0;
	for(int i=1;i<=n;i++){
		while(top && b[st[top]]<b[i])top--;
		if(top)lb[i]=st[top];
		else lb[i]=0;
		st[++top]=i;
	}
	top=0;
	for(int i=n;i>=1;i--){
		while(top && b[st[top]]<b[i])top--;
		if(top)rb[i]=st[top];
		else rb[i]=n+1;
		st[++top]=i;
	}
//	for(int i=1;i<=n;i++)cout<<la[i]<<" ";cout<<endl;
//	for(int i=1;i<=n;i++)cout<<ra[i]<<" ";cout<<endl;
//	for(int i=1;i<=n;i++)cout<<lb[i]<<" ";cout<<endl;
//	for(int i=1;i<=n;i++)cout<<rb[i]<<" ";cout<<endl;
	return;
}
ull query(int u,int l,int r){
	ull ans=0;
//	cout<<u<<" "<<l<<" "<<r<<endl;
	for(int i=l;i<=r;i++){
		ull sl=max(lb[i]+1,l);
		ull sr=min(rb[i]-1,r);
		ull ml=min(u,i);
		ull mr=max(u,i);
//		cout<<i<<" "<<sl<<" "<<sr<<" "<<ml<<" "<<mr<<endl;
		if(ml>=sl && sr>=mr)ans+=b[i]*(ml-sl+1)*(sr-mr+1);
	}
	return ans;
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	pre();q=read();
	for(int i=1;i<=q;i++){
		int l=read(),r=read();
		ull ans=0;
		for(int j=l;j<=r;j++){
			ull sl=max(la[j]+1,l);
			ull sr=min(ra[j]-1,r);
			ans+=query(j,sl,sr)*a[j];
		}
		printf("%llu\n",ans);
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/