#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define pb push_back

struct MinSegTree{
    int n;
    vector<int> dat;

    MinSegTree(){}
    MinSegTree(int _n){
        n = 1;
        while(n<_n) n*=2;
        dat = vector<int>(2*n-1,INT_MAX);
    }
    void update(int k, int val){
        k += n-1;
        dat[k] = val;
        while(k>0){
            k = (k-1)/2;
            dat[k] = min(dat[2*k+1],dat[2*k+2]);
        }
    }
    int _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return INT_MAX;
        if(a<=l && r<=b) return dat[k];

        int vl = _query(a,b,2*k+1,l,(l+r)/2);
        int vr = _query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    int query(int a, int b){
        return _query(a,b,0,0,n);
    }
    int get(int k)
    {
        k += n-1;
        return dat[k];
    }
};


int main()
{
    int n;
    scanf(" %d", &n);

    MinSegTree st[2];
    rep(j,2)
    {
        st[j] = MinSegTree(n);
        rep(i,n)
        {
            int v;
            scanf(" %d", &v);
            st[j].update(i,v);
        }
    }

    int Q;
    scanf(" %d", &Q);

    set<int> u;
    rep(i,n) u.insert(i);

    while(Q--)
    {
        int x,y,z;
        scanf(" %d %d %d", &x, &y, &z);

        --y;

        if(x==1 || x==2)
        {
            st[x-1].update(y,z);
            u.insert(y);
        }
        else if(x==3 || x==4)
        {
            printf("%d\n", st[x-3].query(y,z));
        }
        else
        {
            int focus = !(x-5);
            // printf(" x= %d focus %d\n", x,focus);
            for(int idx:u)
            {
                // st[x-5].update(idx, st[focus].query(idx,idx+1));
                st[x-5].update(idx, st[focus].get(idx));
            }
            u.clear();
        }

        // printf(" --- Q %d \n", Q);
        // printf(" A:");
        // rep(i,n) printf(" %d", st[0].get(i));
        // printf("\n");
        // printf(" B:");
        // rep(i,n) printf(" %d", st[1].get(i));
        // printf("\n");
    }

    return 0;
}
### Prompt

Your task is to create 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define pb push_back

struct MinSegTree{
    int n;
    vector<int> dat;

    MinSegTree(){}
    MinSegTree(int _n){
        n = 1;
        while(n<_n) n*=2;
        dat = vector<int>(2*n-1,INT_MAX);
    }
    void update(int k, int val){
        k += n-1;
        dat[k] = val;
        while(k>0){
            k = (k-1)/2;
            dat[k] = min(dat[2*k+1],dat[2*k+2]);
        }
    }
    int _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return INT_MAX;
        if(a<=l && r<=b) return dat[k];

        int vl = _query(a,b,2*k+1,l,(l+r)/2);
        int vr = _query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    int query(int a, int b){
        return _query(a,b,0,0,n);
    }
    int get(int k)
    {
        k += n-1;
        return dat[k];
    }
};


int main()
{
    int n;
    scanf(" %d", &n);

    MinSegTree st[2];
    rep(j,2)
    {
        st[j] = MinSegTree(n);
        rep(i,n)
        {
            int v;
            scanf(" %d", &v);
            st[j].update(i,v);
        }
    }

    int Q;
    scanf(" %d", &Q);

    set<int> u;
    rep(i,n) u.insert(i);

    while(Q--)
    {
        int x,y,z;
        scanf(" %d %d %d", &x, &y, &z);

        --y;

        if(x==1 || x==2)
        {
            st[x-1].update(y,z);
            u.insert(y);
        }
        else if(x==3 || x==4)
        {
            printf("%d\n", st[x-3].query(y,z));
        }
        else
        {
            int focus = !(x-5);
            // printf(" x= %d focus %d\n", x,focus);
            for(int idx:u)
            {
                // st[x-5].update(idx, st[focus].query(idx,idx+1));
                st[x-5].update(idx, st[focus].get(idx));
            }
            u.clear();
        }

        // printf(" --- Q %d \n", Q);
        // printf(" A:");
        // rep(i,n) printf(" %d", st[0].get(i));
        // printf("\n");
        // printf(" B:");
        // rep(i,n) printf(" %d", st[1].get(i));
        // printf("\n");
    }

    return 0;
}
```