#include <bits/stdc++.h>
using namespace std;
//hope a happy ending =)
//have a nice day~
//freopen
int T,n,q;
int a[250005],b[250005];
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	cin>>T>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	cin>>q;
	while(q--){
		int l,r;
		unsigned long long ans=0;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				unsigned long long maxxa=0,maxxb=0;
				for(int i=p;i<=q;i++){
					maxxa=max(maxxa,(unsigned long long)a[i]);
					maxxb=max(maxxb,(unsigned long long)b[i]);
				}
				ans+=maxxa*maxxb;
			}
		}
		printf("%lld\n",ans);
	}
}
