#include<bits/stdc++.h>
#define ull unsigned long long int
using namespace std;
ull read()
{
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	ull res=ch-48;
	while((ch=getchar())>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+ch-48;
	return res;
}
ull T,n,Q,a[250005][2],tree[1000005][2],ans,ll,rr;
void build(ull k,ull l,ull r,ull g)
{
	if(l==r)
	{
		tree[k][g]=a[l][g];
		return;
	}
	ull mid=l+r>>1;
	build(k<<1,l,mid,g);
	build(k<<1|1,mid+1,r,g);
	tree[k][g]=max(tree[k<<1][g],tree[k<<1|1][g]);
}
ull quiry(ull k,ull l,ull r,ull x,ull y,ull g)
{
	if(x<=l&&r<=y) return tree[k][g];
	ull mid=l+r>>1,maxn=0;
	if(x<=mid) maxn=max(maxn,quiry(k<<1,l,mid,x,y,g));
	if(y>mid) maxn=max(maxn,quiry(k<<1|1,mid+1,r,x,y,g));
	return maxn;
}
int main()
{
	freopen("match.in","r",stdin);freopen("match.out","w",stdout);
	T=read();n=read();
	for(ull i=1;i<=n;++i) a[i][0]=read();
	for(ull i=1;i<=n;++i) a[i][1]=read();
	build(1,1,n,0);build(1,1,n,1);
	Q=read();
	while(Q--)
	{
		ll=read(),rr=read();ans=0;
		for(ull p=ll;p<=rr;++p)
			for(ull q=p;q<=rr;++q)
				ans+=quiry(1,1,n,p,q,0)*quiry(1,1,n,p,q,1);
		cout<<ans<<'\n';
	}
	return 0;
}
