#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MAX_NODE 8000000
struct AVL {
	struct Node {
		Node *l;
		Node *r;
		int val;
		int min;
		int height;
		int size;
		Node *fetch() {
			min = std::min({val, l->min, r->min});
			height = 1 + std::max(l->height, r->height);
			size = 1 + l->size + r->size;
			return this;
		}
		Node *rotate_l() {
			Node *new_root = AVL::new_node(r);
			r = new_root->l;
			new_root->l = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		Node *rotate_r() {
			Node *new_root = AVL::new_node(l);
			l = new_root->r;
			new_root->r = this;
			fetch();
			new_root->fetch();
			return new_root;
		}
		int height_diff() {
			return l->height - r->height;
		}
		Node *balance() {
			int dif = height_diff();
			if (dif == 2) {
				if (l->height_diff() < 0) l = new_node(l)->rotate_l();
				return rotate_r();
			} else if (dif == -2) {
				if (r->height_diff() > 0) r = new_node(r)->rotate_r();
				return rotate_l();
			} else return fetch();
		}
	};
	static Node buf[MAX_NODE];
	static int head;
	static Node *NONE;
	Node *root = NONE;
	AVL() {
		if (!head) buf[head++] = {NONE, NONE, 0, 1000000000, 0, 0};
	}
	static Node *new_node(Node *node) {
		if (node == NONE) return node;
		buf[head] = *node;
		return &buf[head++];
	}
	Node *push_back(Node *node, int val) {
		if (node == NONE) {
			buf[head] = {NONE, NONE, val, val, 1, 1};
			return &buf[head++];
		}
		node = new_node(node);
		node->r = push_back(node->r, val);
		return node->balance();
	}
	Node *assign(Node *node, int index, int val) {
		node = new_node(node);
		int lsize = node->l->size;
		if (index < lsize) node->l = assign(node->l, index, val);
		else if (index > lsize) node->r = assign(node->r, index - lsize - 1, val);
		else node->val = val;
		return node->balance();
	}
	int min(Node *node, int l, int r) {
		if (l <= 0 && r >= node->size) return node->min;
		int lsize = node->l->size;
		int res = 1000000000;
		if (l <= lsize && r > lsize) res = node->val;
		if (l < lsize && node->l != NONE) res = std::min(res, min(node->l, l, r));
		if (r > lsize + 1 && node->r != NONE) res = std::min(res, min(node->r, l - lsize - 1, r - lsize - 1));
		return res;
	}
	void dump(Node *node, std::vector<int> &res) {
		if (node->l != NONE) dump(node->l, res);
		res.push_back(node->val);
		if (node->r != NONE) dump(node->r, res);
	}
	std::vector<int> dump() {
		std::vector<int> res;
		dump(root, res);
		return res;
	}
	void push_back(int val) {
		root = push_back(root, val);
	}
	void assign(int index, int val) {
		root = assign(root, index, val);
	}
	int min(int l, int r) {
		return min(root, l, r);
	}
};
AVL::Node AVL::buf[MAX_NODE];
int AVL::head = 0;
AVL::Node *AVL::NONE = AVL::buf;

int main() {
	int n = ri();
	AVL a, b;
	for (int i = 0; i < n; i++) a.push_back(ri());
	for (int i = 0; i < n; i++) b.push_back(ri());
	int q = ri();
	for (int i = 0; i < q; i++) {
		int t = ri();
		int y = ri();
		int z = ri();
		if (t == 1) a.assign(y - 1, z);
		else if (t == 2) b.assign(y - 1, z);
		else if (t == 3) printf("%d\n", a.min(y - 1, z));
		else if (t == 4) printf("%d\n", b.min(y - 1, z));
		else if (t == 5) a.root = b.root;
		else if (t == 6) b.root = a.root;
		if (i % 15000 == 0) {
			std::vector<int> a_ = a.dump(), b_ = b.dump();
			AVL::head = 1;
			a.root = AVL::NONE;
			b.root = AVL::NONE;
			for (auto i : a_) a.push_back(i);
			for (auto i : b_) b.push_back(i);
		}
	}
	return 0;
}



Measured memory_bytes: 242840