#include<bits/stdc++.h>
using namespace std;
long long ans,a1,l,r,b1,a[10000],b[10000],n,T,Q;
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++){
		scanf("%d %d",&l,&r);
		ans=0;
		for (int j=l;j<=r;j++)
			for (int k=l;k<=r;k++){
				a1=0;b1=0;
				for (int m=j;m<=k;m++){
					a1=max(a[m],a1);
					b1=max(b[m],b1);
				}
				ans+=a1*b1;
			}
		printf("%d\n",ans);
	}
}
