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

int T,n,q;
int a[250005],b[250005];
int lg2[250005],rmqa[500005][30],rmqb[500005][30];

void rmq()
{
	lg2[0]=-1;
	for(int i=1;i<=n;i++)
	{
		rmqa[i][0]=a[i],rmqb[i][0]=b[i],lg2[i]=lg2[i>>1]+1;
	}
	for(int k=1;k<=lg2[n];k++)
	{
		for(int i=1;i<=n;i++)
		{
			rmqa[i][k]=max(rmqa[i][k-1],rmqa[i+(1<<(k-1))][k-1]);
			rmqb[i][k]=max(rmqb[i][k-1],rmqb[i+(1<<(k-1))][k-1]);
		}
	}
}

int rangemaxa(int l,int r)
{
	int k=lg2[r-l+1];
	return max(rmqa[l][k],rmqa[r-(1<<k)+1][k]);
}
int rangemaxb(int l,int r)
{
	int k=lg2[r-l+1];
	return max(rmqb[l][k],rmqb[r-(1<<k)+1][k]);
}

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 i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
	}
	rmq();
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		unsigned long long  ans=0;
		for(int k=1;k<=r-l+1;k++)
		{
			for(int i=l;i<=r-k+1;i++)
			{
				int tmaxa=rangemaxa(i,i+k-1),tmaxb=rangemaxb(i,i+k-1);
				ans=(ans+(unsigned long long)tmaxa*tmaxb);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}