#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[2500000],b[2500000],t,n,q;
int tra[10000000],trb[10000000];
int query(int l,int r)
{
	int maxa=0,maxb=0;
	for(int i=l;i<=r;i++)
	{
		maxa=max(maxa,a[i]);
	}
	for(int i=l;i<=r;i++)
	{
		maxb=max(maxb,b[i]);
	}
	return maxa*maxb;
}
void builda(int l,int r,int p)
{
	if(l==r)
	{
		tra[p]=a[l];
		return;
	}
	int mid=(l+r)/2;
	builda(l,mid,p*2);
	builda(mid+1,r,p*2+1);
	tra[p]=max(tra[p*2],tra[p*2+1]);
}
void buildb(int l,int r,int p)
{
	if(l==r)
	{
		trb[p]=b[l];
		return;
	}
	int mid=(l+r)/2;
	buildb(l,mid,p*2);
	buildb(mid+1,r,p*2+1);
	trb[p]=max(trb[p*2],trb[p*2+1]);
}
int querya(int l,int r,int nowl,int nowr,int p)
{
	if(nowl>=l&&nowr<=r)
	{
		return tra[p];
	}
	int h=0,mid=(nowl+nowr)/2;
	if(l<mid)
	h=max(h,querya(l,r,nowl,mid,p*2));
	if(mid<=r)
	h=max(h,querya(l,r,mid+1,nowr,p*2+1));
	return h;
}
int queryb(int l,int r,int nowl,int nowr,int p)
{
	if(nowl>=l&&nowr<=r)
	{
		return trb[p];
	}
	int h=0,mid=(nowl+nowr)/2;
	if(l<mid)
	h=max(h,queryb(l,r,nowl,mid,p*2));
	if(mid<=r)
	h=max(h,queryb(l,r,mid+1,nowr,p*2+1));
	return h;
}
void sum(int l,int r)
{
	return query(l,r,1,n,1)*query(l,r,1,n,1);
}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>t>>n;
	if(n<=30)
	{
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	cin>>q;
	while(q--)
	{
		int ans=0,l,r;
		cin>>l>>r;
		for(int p=l;p<=r;p++)
		{
			for(int q=p;q<=r;q++)
			{
				ans+=query(p,q);
			}
		}
		cout<<ans<<endl;
	}
	}
	
	else
	{
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	builda(1,n,1);
	buildb(1,n,1);
	cin>>q;
	while(q--)
	{
		int ans=0,l,r;
		cin>>l>>r;
		for(int p=l;p<=r;p++)
		{
			for(int q=p;q<=r;q++)
			{
				ans+=sum(p,q);
			}
		}
		cout<<ans<<endl;
	}	
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}