#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int T,n,Q,l,r;
ll a[100005],b[100005];
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--){
		scanf("%d %d",&l,&r);
		ll ans=0;
		for(int i=l;i<=r;i++){
			ll maxa=a[i],maxb=b[i];
			for(int j=i;j<=r;j++){
				maxa=max(maxa,a[j]);
				maxb=max(maxb,b[j]);
				ans=ans+maxa*maxb;
			//	printf("!%lld\n",maxa*maxb);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}