#include<bits/stdc++.h>
#define LL unsigned long long
using namespace std;
int t,n;
LL a[10100],b[10100];

int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int j=1;j<=n;j++)scanf("%lld",&b[j]);
	int q;
	cin>>q;
	for(int i=1,r,l;i<=q;i++)
	{
		LL ans=0;
		scanf("%d%d",&l,&r);
		LL ma=0,mb=0;
		for(int ll=l;ll<=r;ll++)
		{
			ma=a[ll],mb=b[ll];
			for(int rr=ll;rr<=r;rr++)
			{
				ma=max(ma,a[rr]),mb=max(mb,b[rr]);
				ans=(ans+ma*mb);
			}
		}
		printf("%lld\n",ans);
	}
	
	return 0;
}
/*
0 2
2 1
1 2
1
1 2
*/