#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define N 10000

struct node{
  int key;
  struct node *p,*l,*r;
};
typedef struct node *Node;
Node root;
void insert(int);
void printa(Node);
void printb(Node);
int main()
{
  int m,i,p;
  char ip[10];

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",ip);
    if(ip[0] == 'i'){
      scanf("%d",&p);
      insert(p);
    }
    else {
      printa(root);
      printf("\n");
      printb(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int p)
{
  Node x,y,z;
  y = NIL;
  x = root;
  z = malloc(sizeof(struct node));
  z->key = p;
  z->l = NIL;
  z->r = NIL;

  while (x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else x = x->r;
  }
  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->l = z;
  }
  else y->r = z;
}



void printb(Node j)
{
  if(j == NIL){
    return;
  }
  printf(" %d",j->key);
  printb(j->l);
  printb(j->r);
}

void printa(Node k)
{
  if(k == NIL){
    return;
  }
  printa(k->l);
  printf(" %d",k->key);
  printa(k->r);
}