#include<bits/stdc++.h>
using namespace std;
const int MAXN=300001;
int n,l,r,p,q,t,Q;
int a[MAXN],b[MAXN];
long long ans;
int fmax1(int l,int r){
	int s=a[l];
	for(int i=l+1;i<=r;i++){
		if(s<a[i]) s=a[i];
	}
	return s;
}
int fmax2(int l,int r){
	int s=b[l];
	for(int i=l+1;i<=r;i++){
		if(s<b[i]) s=b[i];
	}
	return s;
}
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 i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				ans+=fmax1(i,j)*fmax2(i,j);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}