#include<bits/stdc++.h>
using namespace std;
unsigned long long T,n,a[3005],b[3005],q,ma,mb;
unsigned long long maxera(unsigned long long l,unsigned long long r){
	unsigned long long temp=0;
	for(unsigned long long i=l;i<=r;i++)temp=max(temp,a[i]);
	return temp;
}
unsigned long long maxerb(unsigned long long l,unsigned long long r){
	unsigned long long temp=0;
	for(unsigned long long i=l;i<=r;i++)temp=max(temp,b[i]);
	return temp;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%llu%llu",&T,&n);
	for(unsigned long long i=1;i<=n;i++)scanf("%llu",&a[i]);
	for(unsigned long long i=1;i<=n;i++)scanf("%llu",&b[i]);
	scanf("%llu",&q);unsigned long long l=0,r=0;
	while(q--){
		unsigned long long ans=0;
		scanf("%llu%llu",&l,&r);
		for(unsigned long long p=l;p<=r;p++){
			for(unsigned long long qq=p;qq<=r;qq++){
				ans+=maxera(p,qq)*maxerb(p,qq);
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}