#include<cstdlib>
#include<cstdio>
#include<iostream>
#define ll unsigned long long
using namespace std;
const ll N=250010;
ll tr[N<<2],f[N<<2],a[N],b[N],last[N],nex[N],Q;
ll sum,t,n,ans,maxxa,maxxb;

int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ll l,r;
	scanf("%lld%lld",&t,&n);
	for(ll i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	for(ll j=1;j<=n;j++)
	  scanf("%lld",&b[j]);
	scanf("%lld",&Q);
	while(Q--)
	{
		scanf("%lld%lld",&l,&r);
		ans=0;
		for(ll i=l;i<=r;i++)
		{
			maxxa=a[i];maxxb=b[i];
		  for(ll j=i;j<=r;j++)
		  {
		  	if(maxxa<a[j]) maxxa=a[j];
		  	if(maxxb<b[j]) maxxb=b[j];
		  	ans+=maxxa*maxxb;
		  }
		}
		printf("%lld\n",ans);
	}

	return 0;
}