#include<bits/stdc++.h>
using namespace std;
unsigned long long t,q,n,i,j,l,r,a[300003],b[300003],c[3003][3003],d[3003][3003],x,y,s;
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%llu%llu",&t,&n);
	for(i=1;i<=n;i=i+1)scanf("%llu",&a[i]);
	for(i=1;i<=n;i=i+1)scanf("%llu",&b[i]);
	for(i=1;i<=n;i=i+1)
	{
		x=0;y=0;
		for(j=i;j<=n;j=j+1)
		{
			x=max(x,a[j]);y=max(y,b[j]);
			c[i][j]=x*y;d[i][j]=d[i][j-1]+c[i][j];
		}
	}
	scanf("%llu",&q);
	for(i=1;i<=q;i=i+1)
	{
		scanf("%llu%llu",&l,&r);s=0;
		for(j=l;j<=r;j=j+1)s=s+d[j][r];
		printf("%llu\n",s);
	}
	return 0;
}
