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