#include<bits/stdc++.h>
#define llu unsigned long long
using namespace std;
llu a[250005],b[250005],ans,t,n,max1,max2,l,r,p,q,s;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
    scanf("%llu%llu",&t,&n);
    for(llu i=1;i<=n;i++)
    {
    	scanf("%llu",&a[i]);
	}
	for(llu i=1;i<=n;i++)
	{
		scanf("%llu",&b[i]);
	}
	scanf("%llu",&s);
	while(s--)
	{
		scanf("%llu%llu",&l,&r);
		max1=max2=ans=0;
		for(llu i=l;i<=r;i++)
		{
			for(llu j=i;j<=r;j++)
			{
				max1=max(max1,a[j]);
				max2=max(max2,b[j]);
				ans=ans+max1*max2;			
			}
			max1=max2=0;
		}
		cout<<ans<<endl;
	}
	return 0;
}