//8opts
#include <bits/stdc++.h>
using namespace std;

const int N=25e4;
long long a[N],b[N];
int n;
unsigned long long ans;

void into(){
	int T;scanf("%d%d",&T,&n);
	for(int i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;++i)
		scanf("%lld",&b[i]);
	ans=0;
}

void solve(int l,int r){
	for(int i=l;i<=r;++i){
		int Ma=a[i],Mb=b[i];
		for(int j=i;j<=r;++j){
			if(a[j]>Ma)	Ma=a[j];
			if(b[j]>Mb)	Mb=b[j];
			ans+=Ma*Mb;
		}
	}
}

void solve(){
	int Q;scanf("%d",&Q);
	while(Q--){
		ans=0;
		int l,r;
		scanf("%d%d",&l,&r);
		solve(l,r);
		cout<<ans<<endl;
	}
}

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	into();
	solve();
	return 0;
}
