#include<bits/stdc++.h>
using namespace std;
const int N=250005;
struct Tree{
	int l,r,p,maxx;
}t[N],tb[N];
int T,Q,n,l,r,a[N],b[N];
unsigned long long anss;
void solve()
{
	scanf("%d%d",&l,&r);anss=(unsigned long long)0;
	for (int i=l;i<=r;i++)
	{
		unsigned long long aa=(unsigned long long)0,bb=(unsigned long long)0;
	    for (int j=i;j<=r;j++)
	    {
	    	aa=max(aa,(unsigned long long)a[j]);bb=max(bb,(unsigned long long)b[j]);
	    	anss=(unsigned long long)(anss+(unsigned long long)(aa*bb));
		}
	}
	cout<<anss<<endl;
	return ;
}
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);
	while (Q--) solve();
	return 0;
}
//rp++
//goodbye OI
