#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;

Node root;

void insert(int k){
  Node *x = root,*y = NIL, *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  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 inorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preoder(u->l);
  preoder(u->r);
}


int main(){
  int n, i, x;
  char com;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    scanf("%s", com);
    if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }
    else if(com == "print"){
      inorder(root);
      printf("\n");
      preoder(root);
      printf("\n");
    }
  }
  return 0;
}
