#include<bits/stdc++.h>
#define LL long long
#define int unsigned long long
using namespace std;
inline LL read(){
	LL res=0,fl=1;
	char ch=getchar();
	while(!(ch>='0' && ch<='9')){
		if(ch=='-')fl=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9')res=res*10+ch-'0',ch=getchar();
	return res*fl;
}
const LL N=1e5+5;
unsigned LL T,n,a[N],b[N],sta[N][32],stb[N][32];
inline int Rmqa(int x,int y){
	int t=log2(y-x+1);
	return max(sta[x][t],sta[y-(1<<t)+1][t]);
}
inline int Rmqb(int x,int y){
	int t=log2(y-x+1);
	return max(stb[x][t],stb[y-(1<<t)+1][t]);
}
signed main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T=read(),n=read();
	for(int i=1;i<=n;i++){
		sta[i][0]=a[i]=read();
	}
	for(int i=1;i<=n;i++){
		stb[i][0]=b[i]=read();
	}
	for(int k=1;k<32;k++){
		for(int i=1;i+(1<<k)-1<=n;i++){
			sta[i][k]=max(sta[i][k-1],sta[i+(1<<k-1)][k-1]);
			stb[i][k]=max(stb[i][k-1],stb[i+(1<<k-1)][k-1]);
		}
	}
	int Q=read();
	while(Q--){
		int l,r,ans=0;
		l=read(),r=read();
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				ans+=Rmqa(p,q)*Rmqb(p,q);
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}
