#include<bits/stdc++.h>
#define rint register int
#define ll long long
#define N 300000
//long long
int a[N],b[N],al[N],bl[N],ar[N],br[N];
ll ans;
//long long mod=18446744073709551616;
int Q;
int l,r;
int T,n;
using namespace std;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d%d",&T,&n);
	for (rint i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (rint i=1;i<=n;i++)
		scanf("%d",&b[i]);
	scanf("%d",&Q);
	for (rint i=1;i<=Q;i++)
	{
		scanf("%d%d",&l,&r);
		ans=1;
		for (rint i=l;i<=r;i++)
			for (rint j=i;j<=r;j++)
			{
				int Maxa=-0x7fffffff;
				int Maxb=-0x7fffffff;
				for (rint k=i;k<=j;k++)
				{
					Maxa=max(a[i],Maxa);
					Maxb=max(b[i],Maxb);
				}
				ans=(((1ll)*ans*Maxa)*Maxb);
			}
		printf("%lld\n",ans);
	}
//	for (rint i=1;i<=n;i++)
//		for (rint j=i-1;j>=1;j--)
//		if (a[i]>=a[j]) al[i]++;else break;
//	for (rint i=1;i<=n;i++)
//		for (rint j=i-1;j>=1;j--)
//		if (b[i]>=b[j]) bl[i]++;else break;
//	for (rint i=1;i<=n;i++)
//		for (rint j=i+1;j<=n;j++)
//		if (a[i]>=a[j]) ar[i]++;else break;
//	for (rint i=1;i<=n;i++)
//		for (rint j=i+1;j<=n;j++)
//		if (b[i]>=b[j]) br[i]++;else break;
//	for (int i=1;i<=n;i++)
//	cout<<al[i]<<" "<<ar[i]<<" "<<bl[i]<<" "<<br[i]<<endl;
	fclose(stdin);fclose(stdout);
	return 0;
}