#include<bits/stdc++.h>
using namespace std;
int T,n,Q,a[3005],b[3005];
int mmax(int s[],int l,int r)
{
	int ans=s[l];
	for(int i=l+1;i<=r;i++)ans=max(ans,s[i]);
	return ans;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(scanf("%d",&Q);Q;Q--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		unsigned long long tot=0;
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++)
				tot+=1ll*mmax(a,p,q)*mmax(b,p,q);
		printf("%llu\n",tot);
	}
	return 0;
}