#include<iostream>
#define int long long
using namespace std;

int T,n,a[250005],b[250005],Q,l,r,ans,max1[1000020],max2[1000020];
void build(int l,int r,int x,int *max,int *n)
{
	if(l == r)
	{
		max[x] = n[l];
		return;
	}
	int mid = (l + r) / 2;
	build(l,mid,x * 2,max,n);
	build(mid + 1,r,x * 2 + 1,max,n);
	if(max[x * 2] > max[x * 2 + 1])max[x] = max[x * 2];
	else max[x] = max[x * 2 + 1];
}
int check(int l,int r,int nl,int nr,int x,int *max)
{
	if(nr < l||nl > r)return 0;
	else if(nl >= l&&nr <= r)return max[x];
	else
	{
		int mid = (nl + nr) / 2;
		int c = check(l,r,nl,mid,x * 2,max);
		int d = check(l,r,mid + 1,nr,x * 2 + 1,max);
		if(c > d)return c;
		else return d;
	}
}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%lld %lld",&T,&n);
	for(int i = 1;i <= n;i++)
		scanf("%lld",a + i);
	for(int i = 1;i <= n;i++)
		scanf("%lld",b + i);
	build(1,n,1,max1,a);
	build(1,n,1,max2,b);
	scanf("%lld",&Q);
	for(int i = 0;i < Q;i++)
	{
		ans = 0;
		scanf("%lld %lld",&l,&r);
		for(int p = l;p <= r;p++)
			for(int q = p;q <= r;q++)
			{
				int maxa = check(p,q,1,n,1,max1),maxb = check(p,q,1,n,1,max2);
				ans += maxa * maxb;
			}
		printf("%lld\n",ans);
	}
}
