#include<bits/stdc++.h>
using namespace std;
int T,n,a[123612],b[123512],q;
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);	
	int T,n,q;
	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 i=1;i<=q;++i){
		int L,R;
		cin>>L>>R;
		unsigned long long ans=0;
		for(int j=L;j<=R;++j)
			for(int k=j;k<=R;++k){
				int M1=0,M2=0;
				for(int z=j;z<=k;++z)
					M1=max(M1,a[z]),M2=max(M2,b[z]);
				ans+=1ull*M1*M2;
			}
			cout<<ans<<'\n';
	}
}