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

 struct NODE{
  int k;
  struct  NODE *p;
  struct NODE *l;
  struct NODE *ri;
};

struct NODE *N,*r;

void ins(int o){
struct NODE *a=N;
struct NODE *b=r;
struct NODE *c;
  c=(struct NODE*)malloc(sizeof(struct NODE));
  
  c->k = o;
  c->l = N;
  c->ri = N;
  while(b!=N){
    a = b;
    if(c->k < b->k){
      b=b->l;
    }
    else{
      b=b->ri;
    } 
  }
  c->p=a;
  if(a==N){
    r=c;
  }
  else{
    if(c->k < a->k){
      a->l=c;
    }
    else{
      a->ri=c;
    }
  }
}

void T(struct NODE *R){
  if(R==N)return;
  T(R->l);
  printf(" %d",R->k);
    T(R->ri);
}

void S(struct NODE *R){
  if(R==N)return;
  printf(" %d",R->k);
  S(R->l);
  S(R->ri);
}


int main(){
  int i,j,o,h;
  char O[10];
  scanf("%d",&o);
  for(i=0;i<o;i++){
    scanf("%s",O);
    if(strlen(O)==6){
      scanf("%d",&h);
      ins(h);
    }
    else{
      T(r);
      printf("\n");
      S(r);
      printf("\n");
    }
  }
  return 0;
}


