#define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  void update(int k,T x){
    dat[k+=n]=x;
    laz[k]=ei;
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}


### Prompt

Generate a CPP solution to the following problem:

Problem

Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.

Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.

Each statement is represented by three integers $ x, y, z $.

* Set the value of the $ y $ item in the sequence $ A $ to $ z $. (When $ x = 1 $)
* Set the value of the $ y $ item in the sequence $ B $ to $ z $. (When $ x = 2 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ A $. (When $ x = 3 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ B $. (When $ x = 4 $)
* Change the sequence $ A $ to be exactly the same as the sequence $ B $. (When $ x = 5 $)
* Change the sequence $ B $ to be exactly the same as the sequence $ A $. (When $ x = 6 $)

Constraints

The input satisfies the following conditions.

* $ 2 \ le N \ le 2 \ times 10 ^ 5 $
* $ 2 \ le Q \ le 2 \ times 10 ^ 5 $
* $ 1 \ le a_i \ le 10 ^ 9 $
* $ 1 \ le b_i \ le 10 ^ 9 $
* $ 1 \ le x_i \ le 6 $
* $ 1 \ le y_i \ le N $ (when $ 1 \ le x_i \ le 4 $)
* $ y_i = -1 $ (when $ x_i = 5, 6 $)
* $ 1 \ le z_i \ le 10 ^ 9 $ (when $ x_i = 1, 2 $)
* $ y_i \ le z_i \ le N $ (when $ x_i = 3, 4 $)
* $ z_i = -1 $ (when $ x_i = 5, 6 $)
* All inputs are integers

Input

The input is given in the following format.

$ N $
$ a_ {1} $ $ a_ {2} $ ... $ a_ {N} $
$ b_ {1} $ $ b_ {2} $ ... $ b_ {N} $
$ Q $
$ x_1 $ $ y_1 $ $ z_1 $
$ x_2 $ $ y_2 $ $ z_2 $
...
$ x_Q $ $ y_Q $ $ z_Q $

Output

Every time a statement of $ x = 3 $ or $ x = 4 $ is given by input, the found value is output on one line.

Example

Input

5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5


Output

7
2
2
8
1

### Response

```cpp
#define NDEBUG 1
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
  void update(int k,T x){
    dat[k+=n]=x;
    laz[k]=ei;
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));      
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  scanf("%d",&n);
  using P = pair<int,int>;
  vector<P> v(n);
  for(int i=0;i<n;i++) scanf("%d",&v[i].first);
  for(int i=0;i<n;i++) scanf("%d",&v[i].second);
  auto f=[](P a,P b){
	   return P(min(a.first,b.first),
		    min(a.second,b.second));
	 };
  auto g=[](P a,P b){
	   if(b.first<0){
	     if(b.second<0) return a;
	     return P(a.second,a.second);
	   }
	   if(b.second<0)
	     return P(a.first,a.first);
	   if(b.second<b.first)
	     return P(a.second,a.second);
	   return P(a.first,a.first);
	 };
  auto h=[](P a,P b){
	   int x=a.first,y=a.second;
	   if(x<0) x=b.first;
	   if(y<0) y=b.second;
	   return P(x,y);
	 };
  
  SegmentTree<P, P, decltype(f), decltype(g), decltype(h)> rmq(n,f,g,h,P(INT_MAX,INT_MAX),P(-1,-1));
  rmq.build(n,v);
  
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    y--;
    if(x==1){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.first=z;
      rmq.update(y,c);
    }
    if(x==2){
      assert(0<=y&&y<n);
      P c=rmq.query(y,y+1);
      c.second=z;
      rmq.update(y,c);
    }
    if(x==3){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.first);
    }
    if(x==4){
      assert(0<=y&&y<z);
      P c=rmq.query(y,z);
      printf("%d\n",c.second);
    }
    if(x==5){
      rmq.query(0,n);
      rmq.update(0,n,P(-1,i));
    }
    if(x==6){
      rmq.query(0,n);
      rmq.update(0,n,P(i,-1));
    }
  }
  return 0;
}


```