#include<bits/stdc++.h>
using namespace std;
long long ans=0;
const int N=250005;
int a[N],b[N];
int T,n;
int l,r;
int Q;
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);
	while(Q--){
		ans=0;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++){
			int mxa=0;
			int mxb=0;
			for(int q=p;q<=r;q++){
				mxa=max(mxa,a[q]);
				mxb=max(mxb,b[q]);
				ans=ans+mxa*mxb;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
