#include<bits/stdc++.h>
using namespace std;
long long read()
{
	long long sum=0,fh=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<3)+(sum<<1)+(ch^48);ch=getchar();}
	return sum*fh;
}
#define Maxn 250010
#define ull unsigned long long
int a[Maxn];
int b[Maxn];
int n,q;
int L[Maxn];
int R[Maxn];
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int id=read();
	n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
	}
	for(int i=1;i<=n;++i)
	{
		b[i]=read();
	}
	int q=read();
	if(n<=30&&q<=30)
	{
		while(q-->0)
		{
			int l=read();
			int r=read();
			ull ans=0;
			for(int x=l;x<=r;++x)
			{
				for(int y=x;y<=r;++y)
				{
					int Mxa=0;
					int Mxb=0;
					for(int j=x;j<=y;++j)
					{
						Mxa=max(Mxa,a[j]);
						Mxb=max(Mxb,b[j]);
					}
					ans+=1ull*Mxa*Mxb;
				}
			}
			printf("%llu\n",ans);
		}
	}
}
