#include<bits/stdc++.h>
using namespace std;
int a[260000],b[260000];
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int i,j,k,p,q,l,r,maxa,maxb,t,n;
	long long ans;
	cin>>t>>n;
	for (i=1;i<=n;i++){
		cin>>a[i];
	}
	for (i=1;i<=n;i++){
		cin>>b[i];
	}
	cin>>q;
	for (k=1;k<=q;k++){
		cin>>l>>r;
		ans=0;
		for (i=l;i<=r;i++){
			for (j=i;j<=r;j++){
				maxa=0;
				maxb=0;
				for (p=i;p<=j;p++){
					maxa=max(maxa,a[p]);
					maxb=max(maxb,b[p]);
				}
				ans=ans+maxa*maxb;
				ans=ans;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}