#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T,n,q;
ll a[35],b[35],ans,ma,mb;
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("%lld",&a[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
	scanf("%d",&q);
	while(q--){
		int l,r;
		scanf("%d%d",&l,&r);
		ans=0;
		for(int i=l;i<=r;i++){
			ma=a[i];
			mb=b[i];
			for(int j=i;j<=r;j++){
				ma=max(ma,a[j]);
				mb=max(mb,b[j]);
				ans+=ma*mb;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
