#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=250010;
int T,n,q,l,r,ans;
int a[N],b[N];
int cal(int l,int r)
{
	int Max1=0,Max2=0;
	for(int i=l;i<=r;++i) {
		if(a[i]>Max1) Max1=a[i];
		if(b[i]>Max2) Max2=b[i];
	}
	return Max1*Max2;
}
void Task1()
{
	for(int i=1;i<=q;++i) {
		cin>>l>>r;
		ans=0;
		for(int j=l;j<=r;++j) {
			for(int k=l;k<=r;++k) {
				ans=ans+cal(j,k);
			}
		}
		cout<<ans<<endl;
	}
}
signed 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;
	Task1();
	return 0;
}
