#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}

typedef struct node
{
	int data;
	struct node* left, * right;
}NODE;

NODE* root = NULL;

void insert(int key)
{
	NODE** p, * new;

	p = &root;

	while (*p != NULL)
	{
		if (key == (*p)->data)
			return NULL;
		else if (key < (*p)->data)
			p = &(*p)->left;
		else
			p = &(*p)->right;
	}

	if ((new = (NODE*)malloc(sizeof(NODE))) == NULL)
		printf("error\n");

	new->left = new->right = NULL;
	new->data = key;
	*p = new;
}

void inorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		inorder(p->left);
		printf(" %d", p->data);
		inorder(p->right);
	}
}

void preorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		printf(" %d", p->data);
		preorder(p->left);
		preorder(p->right);
	}
}

void print_tree(NODE* p)
{
	inorder(p);
	printf("\n");
	preorder(p);
	printf("\n");
}

int main()
{
	int m;
	char str[10];
	int num;

	scanf("%d", &m);

	int i;

	for (i = 0; i < m; i++)
	{
		scanf("%s",str);
		if (strcmp(str, "insert") == 0)
		{
			scanf("%d", &num);
			insert(num);
		}
		else
			print_tree(root);
	}

	return 0;
}
