#include<bits/stdc++.h>
#define maxn 250005
#define int long long
using namespace std;
int n,T,a[maxn],b[maxn],la[maxn],lb[maxn],ra[maxn],rb[maxn],Q[maxn],top,L,R;
unsigned long long Ans,Cnt;
inline int read(){
	int ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-f;ch=getchar();}
	while (ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	read(),n=read();
	for (int i=1;i<=n;i++) a[i]=read(),ra[i]=n+1;
	for (int i=1;i<=n;i++) b[i]=read(),rb[i]=n+1;
	for (int i=1;i<=n;i++){
		while (top&&a[i]>a[Q[top]]) ra[Q[top]]=i,top--;
		Q[++top]=i;
	}
	top=0;
	for (int i=n;i;i--){
		while (top&&a[i]>a[Q[top]]) la[Q[top]]=i,top--;
		Q[++top]=i;
	}
	top=0;
	for (int i=1;i<=n;i++){
		while (top&&b[i]>b[Q[top]]) rb[Q[top]]=i,top--;
		Q[++top]=i;
	}
	top=0;
	for (int i=n;i;i--){
		while (top&&b[i]>b[Q[top]]) lb[Q[top]]=i,top--;
		Q[++top]=i;
	}
	T=read();
	for (int Tt=1;Tt<=T;Tt++){
		L=read(),R=read(),Ans=0;
		for (int i=L;i<=R;i++){
			for (int j=max(L,la[i]+1);j<=min(R,ra[i]-1);j++){
				if (j<=i){
					if (rb[j]-1<i) continue;
					Ans+=a[i]*b[j]*(min(rb[j]-1,min(R,ra[i]-1))-i+1)*(j-max(lb[j]+1,max(L,la[i]+1))+1);
				}
				else{
					if (lb[j]+1>i) continue;
					Ans+=a[i]*b[j]*(i-max(lb[j]+1,max(L,la[i]+1))+1)*(min(rb[j]-1,min(R,ra[i]-1))-j+1);
				}
			}
		}
		printf("%llu\n",Ans);
	}
	return 0;
}