#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef double db;
#define MADE_IN_HEAVEN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ls p<<1
#define rs p<<1|1
const int N=3e5+10;
int t,n,q;
ll a[N],b[N];
ll tra[N<<2],trb[N<<2];
void build(int p,int l,int r){
	if(l==r){
		tra[p]=a[l];
		trb[p]=b[l];
		return;
	}
	int mid=l+r>>1;
	build(ls,l,mid);
	build(rs,mid+1,r);
	tra[p]=max(tra[ls],tra[rs]);
	trb[p]=max(trb[ls],trb[rs]);
	return;
}
ll qua(int p,int l,int r,int ql,int qr){
	if(l>=ql&&r<=qr){
		return tra[p];
	}
	int mid=l+r>>1;
	ll res=0;
	if(mid>=ql) res=max(res,qua(ls,l,mid,ql,qr));
	if(mid<qr) res=max(res,qua(rs,mid+1,r,ql,qr));
	return res;
}
ll qub(int p,int l,int r,int ql,int qr){
	if(l>=ql&&r<=qr){
		return trb[p];
	}
	int mid=l+r>>1;
	ll res=0;
	if(mid>=ql) res=max(res,qub(ls,l,mid,ql,qr));
	if(mid<qr) res=max(res,qub(rs,mid+1,r,ql,qr));
	return res;
}
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	MADE_IN_HEAVEN
	cin>>t>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	cin>>q;
	build(1,1,n);
	int qql,qqr;
	while(q--){
		cin>>qql>>qqr;
		ll ans=0;
		for(int i=qql;i<=qqr;i++){
			for(int j=i;j<=qqr;j++){
				ans+=qua(1,1,n,i,j)*qub(1,1,n,i,j);
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}