#include<bits/stdc++.h>


using namespace std;
const int maxn=3e5+10;
unsigned long long ans=0;
int T,n,Q;
int a[maxn],b[maxn];
int sta[maxn][30],stb[maxn][30];
void stpre(){
	for(int i=1;i<=n;i++)sta[i][0]=a[i],stb[i][0]=b[i];
	int k=log(n)/log(2);
	for(int j=1;j<=k;j++){
		for(int i=1;i<=n-(1<<j)+1;i++){
			sta[i][j]=max(sta[i][j-1],sta[i+(1<<(j-1))][j-1]);
			stb[i][j]=max(stb[i][j-1],stb[i+(1<<(j-1))][j-1]);
		}
	}
}
int qra(int l,int r){
	int k=log(r-l+1)/log(2);
	return max(sta[l][k],sta[r-(1<<k)+1][k]);
}
int qrb(int l,int r){
	int k=log(r-l+1)/log(2);
	return max(stb[l][k],stb[r-(1<<k)+1][k]);
}
int l,r;
int main() {
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	stpre();
	scanf("%d",&Q);
	while(Q--){
		ans=0;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				ans=ans+(unsigned long long)qra(i,j)*(unsigned long long)qrb(i,j);
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}