#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
int i;
int x;

struct Node {
  int k;
  struct Node *r;
  struct Node *l;
  struct Node *p;
};

struct Node *root;
struct Node *NIL;

void insert(int key){

  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));

  z->k = key;
  z->l = NIL;
  z->r = NIL;

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




void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d", u->k);
  preorder(u->l);
  preorder(u->r);
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->k);
  inorder(u->r);
}


char *comin = "insert"; //insert
char *compr = "print"; //print

int main(){

  char *com;

  com = (char*)malloc(10*sizeof(char));  
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s", com);



    
    if(strncmp(com,comin,6)==0){
      scanf("%d",&x);
      insert(x);
    }



    
    else if(strncmp(com,compr,5)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }




  
  return 0;
}

