#include <bits/stdc++.h>
using namespace std;
int t,n,a[300000],b[300000],l,r,q,mm,nn;
long long num;

void maxn(int j,int k);

int main()
{
	freopen ("match.in","r",stdin);
	freopen ("match.out","w",stdout);
	scanf ("%d%d",&t,&n);
	for (int i = 1;i <= n;i++)
		scanf ("%d",&a[i]);
	for (int i = 1;i <= n;i++)
		scanf ("%d",&b[i]);
	scanf ("%d",&q);
	for (int i = 1;i <= q;i++)
		{
			num = 0;
			scanf ("%d%d",&l,&r);
			for (int j = l;j <= r;j++)
				for (int k = j;k <= r;k++)
					{
						maxn(j,k);
						num += mm * nn;
					}
			printf("%lld\n",num);
		}
	return 0;
}
void maxn(int j,int k)
{
	mm = 0,nn = 0;
	for (int i = j;i <= k;i++)
		{
			mm = max(mm,a[i]);
			nn = max(nn,b[i]);
		}
}