#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N=250005;
const int MOD=998244353;
int T,n;
int a[N],b[N];
unsigned long long ans;
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]);
	}
	int q;
	scanf("%d",&q);
	while(q--){
		ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			int maxa=a[i],maxb=b[i];
			for(int j=i;j<=r;j++){
				maxa=max(maxa,a[j]);
				maxb=max(maxb,b[j]);
				ans+=maxa*maxb;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}