#include<bits/stdc++.h>
using namespace std;
int T,n,Q,a[250039],b[250039];
int l,r,p,q,Ma,Mb;
unsigned long long ans;
signed 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);ans=0;
    	for(p=l;p<=r;p++){
    		for(q=p;q<=r;q++){
    			Ma=Mb=0;
    			for(int i=p;i<=q;i++){
    				Ma=max(Ma,a[i]);
    				Mb=max(Mb,b[i]);
				}
				ans+=1ul*Ma*Mb;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}

