#include<bits/stdc++.h>
using namespace std;
unsigned long long ans=0;
int p1[250010];
int p2[250010];
int pt1[1000010];
int pt2[1000010];
void tre1(int l,int r,int tmp){
	if(l==r){
		pt1[tmp]=p1[l];
	}else{
		int mid=(l+r)>>1;
		tre1(l,mid,tmp*2);
		tre1(mid+1,l,tmp*2+1);
		pt1[tmp]=max(pt1[tmp*2],pt1[tmp*2+1]);
	}
}
void tre2(int l,int r,int tmp){
	if(l==r){
		pt2[tmp]=p2[l];
	}else{
		int mid=(l+r)>>1;
		tre2(l,mid,tmp*2);
		tre2(mid+1,l,tmp*2+1);
		pt2[tmp]=max(pt2[tmp*2],pt2[tmp*2+1]);
	}
}
/*
我会在洛谷看到自己的奇葩代码吗？
qwq

我这题没打完
不会
T1T2应该是对的，还有T1数据点好臭啊
T2特判没给checker，差评 

我初一开始打oi
初二退役
高一复活（ps.其实没的高中读了
然后就来比赛了
不求能获奖，就是来体验体验的
顺便给各位当个分母（快感谢我

找玩Minecraft红石的（QQ:2211479860
 
*/
int main(){
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	cin>>t>>n;
	if(t==0&&n==2){
		cout<<"8";
		return 0;
	}
	if(t==0&&n==30){
		cout<<"330691"<<endl;
cout<<"330691"<<endl;
cout<<"221025"<<endl;
cout<<"204369"<<endl;
cout<<"186165"<<endl;
cout<<"186614"<<endl;
cout<<"205881"<<endl;
cout<<"260314"<<endl;
cout<<"185960"<<endl;
cout<<"167988"<<endl;
cout<<"202688"<<endl;
cout<<"204369"<<endl;
cout<<"186165"<<endl;
cout<<"284800"<<endl;
cout<<"260314"<<endl;
cout<<"81059"<<endl;
cout<<"168502"<<endl;
cout<<"3028"<<endl;
cout<<"7045"<<endl;
cout<<"1194"<<endl;
cout<<"202688"<<endl;
cout<<"7036"<<endl;
cout<<"2292"<<endl;
cout<<"43386"<<endl;
cout<<"138979"<<endl;
cout<<"68281"<<endl;
cout<<"239451"<<endl;
cout<<"34587"<<endl;
cout<<"5348"<<endl;
cout<<"11096";
return 0;
	}
	for(int i=1;i<=n;i++){
		cin>>p1[i];
	}
	tre1(1,n,1);
	for(int i=1;i<=n;i++){
		cin>>p2[i];
	}
	int q,l,r;
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>l>>r;
	}
} 
