#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

const int INF = numeric_limits<int>::max();
int main() {
    int n; cin >> n;
    SegmentTree<int> seg1(n, [](int a, int b) { return min(a, b); }, INF);
    SegmentTree<int> seg2(n, [](int a, int b) { return min(a, b); }, INF);
    for (int i = 0; i < n; i++) { int a; cin >> a; seg1.set(i, a); }
    for (int i = 0; i < n; i++) { int b; cin >> b; seg2.set(i, b); }
    seg1.build();
    seg2.build();
    int q; cin >> q;
    vector<pair<int, int>> a_his, a_upd, b_his, b_upd;
    bool init = true;
    #define eb emplace_back
    while (q--) {
        int x, y, z; cin >> x >> y >> z; y--;
        if (x == 1) a_his.eb(y, seg1[y]), seg1.update(y, z), a_upd.eb(y, z);
        if (x == 2) b_his.eb(y, seg2[y]), seg2.update(y, z), b_upd.eb(y, z);
        if (x == 3) cout << seg1.get(y, z) << endl;
        if (x == 4) cout << seg2.get(y, z) << endl;
        if (x == 5) {
            if (init) {
                for (int i = 0; i < n; i++) seg1.update(i, seg2[i]);
                init = false;
            } else {
                reverse(a_his.begin(), a_his.end());
                for (auto &p: a_his) seg1.update(p.first, p.second);
                for (auto &p: b_upd) seg1.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
        if (x == 6) {
            if (init) {
                for (int i = 0; i < n; i++) seg2.update(i, seg1[i]);
                init = false;
            } else {
                reverse(b_his.begin(), b_his.end());
                for (auto &p: b_his) seg2.update(p.first, p.second);
                for (auto &p: a_upd) seg2.update(p.first, p.second);
            }
            a_his.clear(), a_upd.clear(), b_his.clear(), b_upd.clear();
        }
    }
    return 0;
}
