#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,t;
long long ans;
int tr1[N],tr2[N],a[300000],b[300000];
void build1(int l,int r,int rt)
{
	if(l==r)
	{
		tr1[rt]=a[r];
		return ;
	}
	int m=(l+r)/2;
	build1(l,m,rt<<1),build1(m+1,r,(rt<<1)+1);
	tr1[rt]=max(tr1[rt<<1],tr1[(rt<<1)+1]);
}
void build2(int l,int r,int rt)
{
	if(l==r)
	{
		tr2[rt]=b[r];
		return ;
	}
	int m=(l+r)/2;
	build2(l,m,rt<<1),build2(m+1,r,(rt<<1)+1);
	tr2[rt]=max(tr2[rt<<1],tr2[(rt<<1)+1]);
}
int qus1(int L,int R,int l,int r,int rt)
{
	if(R<l||r<L)return 0;
	if(l<=L&&R<=r)return tr1[rt];
	int m=(L+R)/2;
	return max(qus1(L,m,l,r,rt<<1),qus1(m+1,R,l,r,(rt<<1)+1));
}
int qus2(int L,int R,int l,int r,int rt)
{
	if(R<l||r<L)return 0;
	if(l<=L&&R<=r)return tr2[rt];
	int m=(L+R)/2;
	return max(qus2(L,m,l,r,rt<<1),qus2(m+1,R,l,r,(rt<<1)+1));
}
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]);
	}
	build1(1,n,1),build2(1,n,1);
	int k;
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		ans=0;
		int l,r;
		scanf("%d %d",&l,&r);
		for(int p=l;p<=r;p++)
		{
			for(int q=p;q<=r;q++)
			{
				long long m1= (long long)qus1(1,n,p,q,1);
				long long m2=(long long)qus2(1,n,p,q,1);
				long long sum=m1*m2;
				ans+=sum;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
