#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Node{
    int val;
    Node* lhs, *rhs;
    Node(int val):val(val),lhs(nullptr),rhs(nullptr){}
};

Node* update(Node* t,int l, int r,int k,int x){
    if(k<l||r<=k)return t;
    if(l+1==r){
        Node* ret = new Node(x);
        return ret;
    }
    int mid=(l+r)/2;
    Node* ret = new Node(inf);
    ret->lhs = update(t->lhs,l,mid,k,x);
    ret->rhs = update(t->rhs,mid,r,k,x);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}

int query(Node* t,int a,int b, int l, int r){
    if(b<=l||r<=a)return inf;
    if(a<=l&&r<=b)return t->val;
    int vl = query(t->lhs, a,b,l,(l+r)/2);
    int vr = query(t->rhs, a,b,(l+r)/2, r);
    return min(vl,vr);
}

Node* build(vector<int>& v, int l, int r){
    Node* ret = new Node(inf);
    if(l+1==r){
        ret->val=v[l];
        return ret;
    }
    ret->lhs = build(v,l,(l+r)/2);
    ret->rhs = build(v,(l+r)/2,r);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}
int main(){
    int n;
    cin>>n;
    int m=1;
    while(m<n)m*=2;
    vector<int> a(m,inf), b(m,inf);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    Node* A = build(a,0,m);
    Node* B = build(b,0,m);
    int q;
    cin>>q;
    while(q--){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        --y;
        if(x==1){
            A = update(A, 0, m, y, z);
        }
        if(x==2){
            B = update(B, 0, m, y, z);
        }
        if(x==5){
            A = B;
        }
        if(x==6){
            B = A;
        }
        if(x==3){
            printf("%d\n",query(A,y,z,0,m));
        }
        if(x==4){
            printf("%d\n",query(B,y,z,0,m));
        }
    }
    return 0;
}

### Prompt

Your challenge is to write 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
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Node{
    int val;
    Node* lhs, *rhs;
    Node(int val):val(val),lhs(nullptr),rhs(nullptr){}
};

Node* update(Node* t,int l, int r,int k,int x){
    if(k<l||r<=k)return t;
    if(l+1==r){
        Node* ret = new Node(x);
        return ret;
    }
    int mid=(l+r)/2;
    Node* ret = new Node(inf);
    ret->lhs = update(t->lhs,l,mid,k,x);
    ret->rhs = update(t->rhs,mid,r,k,x);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}

int query(Node* t,int a,int b, int l, int r){
    if(b<=l||r<=a)return inf;
    if(a<=l&&r<=b)return t->val;
    int vl = query(t->lhs, a,b,l,(l+r)/2);
    int vr = query(t->rhs, a,b,(l+r)/2, r);
    return min(vl,vr);
}

Node* build(vector<int>& v, int l, int r){
    Node* ret = new Node(inf);
    if(l+1==r){
        ret->val=v[l];
        return ret;
    }
    ret->lhs = build(v,l,(l+r)/2);
    ret->rhs = build(v,(l+r)/2,r);
    ret->val = min(ret->lhs->val, ret->rhs->val);
    return ret;
}
int main(){
    int n;
    cin>>n;
    int m=1;
    while(m<n)m*=2;
    vector<int> a(m,inf), b(m,inf);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    Node* A = build(a,0,m);
    Node* B = build(b,0,m);
    int q;
    cin>>q;
    while(q--){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        --y;
        if(x==1){
            A = update(A, 0, m, y, z);
        }
        if(x==2){
            B = update(B, 0, m, y, z);
        }
        if(x==5){
            A = B;
        }
        if(x==6){
            B = A;
        }
        if(x==3){
            printf("%d\n",query(A,y,z,0,m));
        }
        if(x==4){
            printf("%d\n",query(B,y,z,0,m));
        }
    }
    return 0;
}

```