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