#include<bits/stdc++.h>
using namespace std;
#define rt register int
int T,n,Q,l,r;
long long ans=0;
int a[250005],b[250005];
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(rt i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(rt i=1;i<=n;++i)
		scanf("%d",&b[i]);
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d",&l,&r);
		ans=0;
		int max1,max2;
		for(rt p=l;p<=r;++p)
			for(rt q=p;q<=r;++q){
				max1=-1;max2=-1;
				for(rt i=p;i<=q;++i)
				{
					if(a[i]>max1)max1=a[i];
					if(b[i]>max2)max2=b[i];
				}
				ans=ans+max1*max2;
			}
		printf("%lld\n",ans);		
	}
	return 0;
}