#include<bits/stdc++.h>
using namespace std;
//wo shi yukiyo
//t4 yi yan xian duan shu hao beng kui
//wo mei you zhong wen shu ru fa hao nan shou
//zhe da gai shi wo zui hou yi ci bi sai li
//wo qi shi jue de wo ke neng na bu dao jiang le,
//yin wei di yi ti lian yang li dou mei you tui chu lai
//dan shi wo hai shi hen gan xie he wo tong ji fang de tong xue men
//hai you wo de jiao lian
//wo xi wang neng na ge sheng san
//dan da gai bu tai ke neng
//ying gai shi xie gua le
//zhe ge wen zi gu ji hen nan du,xiao si
//wo de luo gu ming shi xueye(hanzi)yukiyo,id wo wang le
//wo bu jie yi zhe xie sui sui nian bei gua dao mi huo xing wei shang(
//er qie hai hui hen kai xin(
//zhu suo you de kao sheng noip 2022 rp++!!
//12 dian ban wo qu shang ge ce suo
//luo gu shuo wo jin tian yi shang ce suo xiao si le

//di si ti xie gua la..wo ben lai xiang da ge bao li de,pao bu liao
//wo fu le yang li guo bu qu aaa
//..jiao ge yun xing bu liao de ba mei zhe le

//wo hao xiang bao kong jian le
//55,xian duan shu si le,ke xi wo zhi ji de xian duan shu le

//const unsigned long long mod=18446744073709551615;
int ans1[1005],ans2[1005],a[255],b[255];
long long ans=0;
int ls(int p){ return p<<1;}
int rs(int p){ return p<<1|1;}
void pu(int p){
	ans1[p]=max(ans1[ls(p)],ans1[rs(p)]);
	ans2[p]=max(ans2[ls(p)],ans2[rs(p)]);
}
void build(int p,int l,int r){
	if(l==r){
		ans1[p]=a[l];
		ans2[p]=b[l];
		return;
	}
	int mid=(l+r)>>1;
	build(ls(p),l,mid);
	build(rs(p),mid+1,r);
	pu(p);
}
int query1(int ql,int qr,int p,int l,int r){
	int res=0;
	if(ql<=l&&r<=qr){
		return ans1[p];
	}
	int mid=(l+r)>>1;
	if(ql<=mid) res=max(res,query1(ql,qr,ls(p),l,mid));
	if(qr>mid) res=max(res,query1(ql,qr,rs(p),mid+1,r));
	return res;
}
int query2(int ql,int qr,int p,int l,int r){
	int res=0;
	if(ql<=l&&r<=qr){
		return ans2[p];
	}
	int mid=(l+r)>>1;
	if(ql<=mid) res=max(res,query1(ql,qr,ls(p),l,mid));
	if(qr>mid) res=max(res,query1(ql,qr,rs(p),mid+1,r));
	return res;
}

int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	int rp=1;
	while(rp<=2022){
		rp++;
	}
	int t,n;
	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,1,n);
	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		for(int i=l;i<=r;i++){
			for(int j=i;j<=r;j++){
				ans+=(1ll*query1(i,j,1,1,n)*query2(i,j,1,1,n));
			}
		}
		cout<<ans-1<<endl;
	}
	return 0;
}