#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=250005;
int Q,id,n,a[N],b[N];
int main(){
//	freopen("match.in","r",stdin);
//	freopen("match.out","w",stdout);
	scanf("%d%d",&id,&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<=n;i++)scanf("%d",b+i);
	scanf("%d",&Q);
	int l,r;
	while(Q--){
		ull ans=0;
		scanf("%d%d",&l,&r);
		for(int x=l;x<=r;x++){
			for(int y=x;y<=r;y++){
				int A=0,B=0;
				for(int k=x;k<=y;k++)
					A=max(A,a[k]),
					B=max(B,b[k]);
				ans+=1ull*A*B;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}