#include <bits/stdc++.h>
  using namespace std;
int id,n,m,u,v;
unsigned long long a[250005],b[250005],su[1000005],sv[1000005],ans;
bool c,d,e,f;
int read()
{
	int p=1,w=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-') p=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		w=w*10+c-'0';
		c=getchar();
	}
	return p*w;
}
unsigned long long uread()
{
	unsigned long long p=1,w=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-') p=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		w=w*10+c-'0';
		c=getchar();
	}
	return p*w;
}
void write(unsigned long long t)
{
	if (t/10) write(t/10);
	putchar('0'+t%10);
}
void build(int t,int l,int r)
{
	if (l==r)
	{
		su[t]=a[l];
		sv[t]=b[l];
		return;
	}
	int mid=(l+r)>>1;
	build(t<<1,l,mid);
	build(t<<1|1,mid+1,r);
	su[t]=max(su[t<<1],su[t<<1|1]);
	sv[t]=max(sv[t<<1],sv[t<<1|1]);
}
unsigned long long aska(int t,int l,int r,int u,int v)
{
	if (u<=l && r<=v) return su[t];
	int mid=(l+r)>>1;
	unsigned long long ans=0;
	if (u<=mid) ans=aska(t<<1,l,mid,u,v);
	if (v>mid) ans=max(ans,aska(t<<1|1,mid+1,r,u,v));
	return ans;
}
unsigned long long askb(int t,int l,int r,int u,int v)
{
	if (u<=l && r<=v) return sv[t];
	int mid=(l+r)>>1;
	unsigned long long ans=0;
	if (u<=mid) ans=askb(t<<1,l,mid,u,v);
	if (v>mid) ans=max(ans,askb(t<<1|1,mid+1,r,u,v));
	return ans;
}
signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	id=read();
	n=read();
	c=1;
	d=1;
	e=1;
	f=1;
	for (int i=1;i<=n;i++)
	{
		a[i]=uread();
		if (i==1) continue;
		if (a[i]<a[i-1]) c=0;
		else e=0;
	}
	for (int i=1;i<=n;i++)
	{
		b[i]=uread();
		if (i==1) continue;
		if (b[i]<b[i-1]) d=0;
		else f=0;
	}
	build(1,1,n);
	m=read();
	while (m--)
	{
		ans=0;
		u=read();
		v=read();
		for (int i=u;i<=v;i++)
		{
			for (int j=i;j<=v;j++)
			{
				ans+=aska(1,1,n,i,j)*askb(1,1,n,i,j);
			}
		}
		write(ans);
		putchar('\n');
	}
	return 0;
}
