#include<bits/stdc++.h>
using namespace std;
int n,q,a[41],b[41];
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T;
	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--){
		unsigned long long ans=0;
		int maxn1=0,maxn2=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				maxn1=0,maxn2=0;
				for(int k=i;k<=j;k++){
					maxn1=max(maxn1,a[k]);
					maxn2=max(maxn2,b[k]);
				}
				ans=(ans+maxn2*maxn1);
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
