#include<bits/stdc++.h>
#define int long long
using namespace std;
int id,n,t,l,r,a[1000001],b[1000001],ans;
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%lld%lld",&id,&n);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	scanf("%lld",&b[i]);
	scanf("%lld",&t);
	while(t--)
	{
		ans=0;
		scanf("%lld%lld",&l,&r);
		for(int i=l;i<=r;i++)
		for(int j=i;j<=r;j++)
		{
			int maxn=0,maxx=0;
			for(int p=i;p<=j;p++)
			{
				maxn=max(maxn,a[p]);
				maxx=max(maxx,b[p]);
			}
			ans+=maxn*maxx;
		}
		printf("%lld\n",ans);
	}
}