#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL id,n,T,l,r,awa;
LL ans;
LL a[250005],b[250005];
int maxa(int z,int y){
	int maxn=a[z];
	for(int i=z+1;i<=y;i++)if(maxn<a[i])maxn=a[i];
	return maxn;
}
int maxb(int z,int y){
	int maxn=b[z];
	for(int i=z+1;i<=y;i++)if(maxn<b[i])maxn=b[i];
	return maxn;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>id>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	cin>>T;
	while(T--){
		ans=0;
		cin>>l>>r;
		for(int i=l;i<=r;i++)
			for(int j=i;j<=r;j++)
				ans+=maxa(i,j)*maxb(i,j);
		cout<<ans<<'\n';
	}
}