#include<bits/stdc++.h>
using namespace std;
int a[250001],b[250001];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t,n,q,l,r,ma,mb,i,j,k;
	unsigned long long s;
	cin>>t>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=n;i++)
	cin>>b[i];
	cin>>q;
	while(q--)
	{
		cin>>l>>r;s=0;
		for(j=l;j<=r;j++)
		for(k=j;k<=r;k++)
		{
			ma=0,mb=0;
			for(i=j;i<=k;i++)
			{
				ma=max(ma,a[i]);
				mb=max(mb,b[i]);
			}
			s+=(long long)ma*mb;
		}
		printf("%llu\n",s);
	}
	return 0;
}
