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

ll t1[1000005],t2[1000005],a[250006],b[250006];
ll n,T,q,l,r;

inline ll ls(int p){return p<<1;}
inline ll rs(int  p){return p<<1|1;}

inline void push_up(ll p){
	t1[p]=max(t1[ls(p)],t1[rs(p)]);
	t2[p]=max(t2[ls(p)],t2[rs(p)]);
}

void build(ll l,ll r,ll p){
	if(l==r){
		t1[p]=a[l];
		t2[p]=b[l];
		return ;
	}
	ll mid=(l+r)>>1;
	build(l,mid,ls(p));
	build(mid+1,r,rs(p));
	push_up(p);
}

ll search1(ll l,ll r,ll nl,ll nr,ll p){
	ll res=-1000000000000;
	if((l<=nl)&&(nr<=r)){
		return t1[p];
	}
	ll mid=(nl+nr)>>1;
	if(mid>=l) res=max(res,search1(l,r,nl,mid,ls(p)));
	if(mid<r) res=max(res,search1(l,r,mid+1,nr,rs(p)));
	return res;
}

ll search2(ll l,ll r,ll nl,ll nr,ll p){
	ll res=-1e17;
	if((l<=nl)&&(nr<=r)){
		return t2[p];
	}
	ll mid=(nl+nr)>>1;
	if(mid>=l) res=max(res,search2(l,r,nl,mid,ls(p)));
	if(mid<r) res=max(res,search2(l,r,mid+1,nr,rs(p)));
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	
	cin>>T>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	build(1,n,1);
	cin>>q;
	for(int i=1;i<=q;i++){
		ll res=0;
		cin>>l>>r;
		for(int e=l;e<=r;e++){
			for(int k=0;k+e<=r;k++){
				res+=search1(e,e+k,1,n,1)*search2(e,e+k,1,n,1);
			}
		}
		cout<<res<<'\n';
	}
	
	return 0;
}
