#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N=5e5+10;
int T,n,Q;
int a[N],b[N];
struct Tree
{
	int maxx,l,r;
}tree[N<<2],tree2[N<<2];
void pushup(int rt)
{
	tree[rt].maxx=max(tree[rt*2].maxx,tree[rt*2+1].maxx);
}
void pushup2(int rt)
{
	tree2[rt].maxx=max(tree2[rt*2].maxx,tree2[rt*2+1].maxx);
}
void build(int rt,int l,int r)
{
	tree[rt].l=l,tree[rt].r=r;
	if(l==r)
	{
		tree[rt].maxx=a[l];
		return;
	}
	int mid=(l+r)/2;
	build(rt*2,l,mid);
	build(rt*2+1,mid+1,r);
	pushup(rt);
}
void build2(int rt,int l,int r)
{
	tree2[rt].l=l,tree2[rt].r=r;
	if(l==r)
	{
		tree2[rt].maxx=b[l];
		return;
	}
	int mid=(l+r)/2;
	build2(rt*2,l,mid);
	build2(rt*2+1,mid+1,r);
	pushup2(rt);
}
int query(int rt,int L,int R)
{
	int res=0;
	if(L<=tree[rt].l&&tree[rt].r<=R)
	{
		return tree[rt].maxx;
	}
	int mid=(tree[rt].l+tree[rt].r)/2;
	if(L<=mid)
		res=max(res,query(rt*2,L,R));
	if(R>mid)
		res=max(res,query(rt*2+1,L,R));
	return res;
}
int query2(int rt,int L,int R)
{
	int res=0;
	if(L<=tree2[rt].l&&tree2[rt].r<=R)
	{
		return tree2[rt].maxx;
	}
	int mid=(tree2[rt].l+tree2[rt].r)/2;
	if(L<=mid)
		res=max(res,query2(rt*2,L,R));
	if(R>mid)
		res=max(res,query2(rt*2+1,L,R));
	return res;
}
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]);
	build(1,1,n);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	build2(1,1,n);
	scanf("%d",&Q);
	
//	cout<<1<<endl;
	while(Q--)
	{
		ll ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
//		printf("%d\n",query(1,l,r));
		for(int p=l;p<=r;p++)
		{
			for(int q=p;q<=r;q++)
			{
				ll x=query(1,p,q);
				ll y=query2(1,p,q);
				ans+=x*y;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
0 2
2 1
1 2
1
1 2

0 5
1 2 3 4 5
1 2 3 4 5
5
1 3
2 5
1 5 
4 4
2 4
*/