#include <bits/stdc++.h>
using namespace std;


int T,n,Q,l,r,mxa,mxb,a[250005],b[250005];
unsigned long long 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]);
	scanf("%d",&Q);
	
	while(Q--)
	{
		ans=0;
		scanf("%d%d",&l,&r);
		
		for(int i=l;i<=r;i++)//mei ju p
		{
			for(int j=i;j<=r;j++)//mei ju q
			{
				mxa=mxb=0;
				for(int k=i;k<=j;k++)//cong p zhao dao q;
					mxa=max(mxa,a[k]),mxb=max(mxb,b[k]);
				ans+=1ll*mxa*mxb;
			}
		}
		
		cout << ans << '\n';
	}
	
	
	return 0;
	
}
