#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
const int N=3e5+5;//MOD jiu shi ULL de zi ran yi chu
struct node{
	int l,r;
	int max;
}tra[N*4],trb[N*4];
int T,n,Q;
int a[N],b[N];
void pushup(int u,node *tr)
{
	tr[u].max=max(tr[u<<1].max,tr[u<<1|1].max);
}
void build(int u,int l,int r,int w[],node *tr)
{
	if(l==r) tr[u]={l,r,w[l]};
	else
	{
		tr[u]={l,r};
		int mid=l+r>>1;
		build(u<<1,l,mid,w,tr);
		build(u<<1|1,mid+1,r,w,tr);
		pushup(u,tr);
	}
}
int query(int u,int l,int r,node tr[])
{
	int ans=-0x3f3f3f3f;
	if(tr[u].l>=l&&tr[u].r<=r) return tr[u].max;
	else
	{
		int mid=tr[u].l+tr[u].r>>1;
		if(l<=mid) ans=max(ans,query(u<<1,l,r,tr));
		if(r>mid) ans=max(ans,query(u<<1|1,l,r,tr));
	}
	return ans;
}
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]);
	build(1,1,n,a,tra);
	build(1,1,n,b,trb);
	scanf("%d",&Q);
	while(Q--)
	{
		int l,r;
		ULL ans=0;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++)
			{
				ULL ma=(ULL)query(1,p,q,tra),mb=(ULL)query(1,p,q,trb);
				ans+=ma*mb;
			}
		cout<<ans<<"\n";
	}
	return 0;
}
