#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=250001;
int T,n,Q;
int a[MAXN];
int b[MAXN];
int cul(int l,int r)
{
	int maxa=0,maxb=0;
	for(int x1=l;x1<=r;x1++)
		maxa=max(maxa,a[x1]),maxb=max(maxb,b[x1]);
	return maxa*maxb;
}
int main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	scanf("%d %d",&T,&n);
	for(int x1=1;x1<=n;x1++) scanf("%d",&a[x1]);
	for(int x1=1;x1<=n;x1++) scanf("%d",&b[x1]);
	scanf("%d",&Q);
	while(Q--)
	{
		int l,r;
		ll ans=0;
		scanf("%d %d",&l,&r);
		for(int p=l;p<=r;p++)
			for(int q=p;q<=r;q++)
			{
				ans+=cul(p,q);
			}
		printf("%lld\n",ans);
	}
	return 0;
}
