#include<bits/stdc++.h>
using namespace std;
int T,n;
long long ans;
int a[40];
int b[40];
int Q;
void work(){
	int l,r;
	scanf("%d%d",&l,&r);
	for(int p=l;p<=r;p++){
		for(int q=p;q<=r;q++){
			int mxa=-1;
			int mxb=-1;
			for(int i=p;i<=q;i++)mxa=max(mxa,a[i]),mxb=max(mxb,b[i]);
			ans+=1ll*mxa*mxb;
		}
	}
	printf("%lld\n",ans);
}
int main(){
	srand(time(0));
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	//put my code here
	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--)work();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
