#include<bits/stdc++.h>
using namespace std;
const int N=2.5e5+5;
int T,n,a[N],b[N],q;
unsigned long long ans;
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);
	scanf("%d",&q);
	for(int i=1,l,r;i<=q;i++){
		ans=0;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++){
				int ma=0,mb=0;
				for(int j=p;j<=q;j++)ma=max(ma,a[j]);
				for(int j=p;j<=q;j++)mb=max(mb,b[j]);
				ans=ans+ma*mb;	
			}
		printf("%llu\n",ans);
	}
	return 0;
}