#include<bits/stdc++.h>
#define Dtmyj trash
#define ll long long
#define db double
using namespace std;

unsigned ll ans;
int T,n,a[250005],b[250005],Q,l,r;

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--){
		ans=0;
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++){
			for(int q=p;q<=r;q++){
				int maxa=0,maxb=0;
				for(int i=p;i<=q;i++){
					maxa=max(a[i],maxa);
					maxb=max(b[i],maxb);
				}
				ans+=(unsigned ll)maxa*maxb;
			}
		}
		printf("%u\n",ans);
	}
    return 0;
}
