#include<bits/stdc++.h>
using namespace std;
int a[3005];
int b[3005];
int main()
{
	//it's my first show in NOIP,
	//but i'm not satisfied.the grade will be 100+pts
	//i will try my best nxt year
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int T,n,i,Q;
	scanf("%d%d",&T,&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) scanf("%d",&b[i]);
	scanf("%d",&Q);
	while (Q--)
	{
		int sum=0,l,r,p,q,k;
		scanf("%d%d",&l,&r);
		for (p=l;p<=r;p++)
		  for (q=p;q<=r;q++)
		  {
		  	int A=0,B=0;
		  	for (k=p;k<=q;k++)
		  	  A=max(A,a[k]),B=max(B,b[k]);
		  	  sum=sum+A*B;
		  }
		printf("%d\n",sum);
	}
	return 0;
}
