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

const int N=2e6+6;
int T,n,a[N],b[N],Q,l,r,ta[N<<2],tb[N<<2];
unsigned long long ans;

void builda(int l,int r,int p)
{
	if(l==r)	
	{
		ta[p]=a[l];
		return ;
	}
	int mid=(l+r)>>1;
	if(l<=mid)
		builda(l,mid,p<<1);
	else
		builda(mid+1,r,(p<<1)+1);
}
void buildb(int l,int r,int p)
{
	if(l==r)
	{
		tb[p]=b[l];
		return ;
	}
	int mid=(l+r)>>1;
	if(l<=mid)
		buildb(l,mid,p<<1);
	else
		buildb(mid+1,r,(p<<1)+1);
}

int finda(int l,int r,int p)
{
	int maxn=0;
	if(l==r)
		return ta[p];
	int mid=(l+r)>>1;
	if(l<=mid)
		maxn=max(maxn,finda(l,mid,p>>1));
	else
		maxn=max(maxn,finda(mid+1,r,(p>>1)+1));
	return maxn;
}

int findb(int l,int r,int p)
{
	int maxn=0;
	if(l==r)
		return tb[p];
	int mid=(l+r)>>1;
	if(l<=mid)
		maxn=max(maxn,findb(l,mid,p>>1));
	else
		maxn=max(maxn,findb(mid+1,r,(p>>1)+1));
	return maxn;
}

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 j=1;j<=n;j++)
		scanf("%d",&b[j]);
	builda(1,n,1);
	buildb(1,n,1);
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++)
			for(int j=l;j<=r;j++)
			{
				int aa=finda(l,r,1);
				int bb=findb(l,r,1);
				ans=ans+aa*bb;
			}
		printf("%llu\n",ans);
	}
	return 0;
}