#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
const int NUM=250005;
int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9')
	{
		x=x*10+(c-'0');
		c=getchar();
	}
	return x*f;
}
int n,m;
ULL ans,a[NUM],b[NUM];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ULL x,y;
	int l,r;
	read(),n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	m=read();
	for(int i=1;i<=m;i++)
	{
		ans=0;
		l=read(),r=read();
		for(int p=l;p<=r;p++)
		{
			x=y=0;
			for(int q=p;q<=r;q++)
			{
				x=max(x,a[q]);
				y=max(y,b[q]);
				ans+=x*y;
			}
		}
		printf("%llu\n",ans);
	}
}