#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

template<class T>
class BinarySearchTree {
public:
	class Node {
	public:
		Node *parent;
		Node *left;
		Node *right;
		T value;

		Node() : parent(nullptr), left(nullptr), right(nullptr) {}
	};

	Node* root;

	BinarySearchTree() : root(nullptr) {}

	void insert(T value) {
		Node *parent = root;
		Node *node = new Node;

		node->value = value;
		while (parent != nullptr) {
			node->parent = parent;
			if (node->value < parent->value)
				parent = parent->left;
			else
				parent = parent->right;
		}

		if (parent == root) {
			root = node;
		}
		else {
			if (node->value < node->parent->value)
				node->parent->left = node;
			else
				node->parent->right = node;
		}
	}

	vector<T> getPreOrder() {
		vector<T> dst;
		calcPreOrder(dst, root);
		return dst;
	}

	void calcPreOrder(vector<T>& order, Node *node) {
		if (node == nullptr)
			return;
		order.push_back(node->value);
		calcPreOrder(order, node->left);
		calcPreOrder(order, node->right);
	}

	vector<T> getInOrder() {
		vector<T> dst;
		calcInOrder(dst, root);
		return dst;
	}

	void calcInOrder(vector<T>& order, Node *node) {
		if (node == nullptr)
			return;
		calcInOrder(order, node->left);
		order.push_back(node->value);
		calcInOrder(order, node->right);
	}

	vector<T> getPostOrder() {
		vector<T> dst;
		calcPostOrder(dst, root);
		return dst;
	}

	void calcPostOrder(vector<T>& order, Node *node) {
		if (node == nullptr)
			return;
		calcPostOrder(order, node->left);
		calcPostOrder(order, node->right);
		order.push_back(node->value);
	}
};

template<class T>
void printVector(vector<T> v, string between, int mode) {
	if (mode == 0) {
		for (int i = 0, k = v.size(); i < k; ++i) {
			cout << v[i];
			if (i < k - 1)
				cout << between;
		}
		cout << endl;
	}
	else if (mode == 1) {
		for (int i = 0, k = v.size(); i < k; ++i) {
			cout << between << v[i];
		}
		cout << endl;
	}
}

int main() {
	BinarySearchTree<int> tree;
	int n, k;
	string s;

	cin >> n;
	while (n--) {
		cin >> s;
		if (s == "insert") {
			cin >> k;
			tree.insert(k);
		}
		else if (s == "print") {
			printVector(tree.getInOrder(), " ", 1);
			printVector(tree.getPreOrder(), " ", 1);
		}
	}

	return 0;
}

Measured memory_bytes: 30356