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

struct Node1{
  int key1;
  struct Node1 *left,*right,*parent;
};
  
struct Node1 *root,*NIL;
void insert(int );
void ins_order(struct Node1 *);
void pri_order(struct Node1 *);
int main(){
  int k,i,x;
  char order[7];
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
    scanf("%d",&x);
    insert(x);
    }else if(strcmp(order,"print")==0){
    ins_order(root);
    printf("\n");
    pri_order(root);
    printf("\n");
    }
  }
  return 0;
}
void insert(int a){
 struct  Node1 *x=root;
 struct Node1 *y=NIL;
 struct  Node1 *z;

  z=(struct Node1 *)malloc(sizeof(struct Node1));
  z->key1=a;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key1 < x->key1){
      x= x->left;
    }else{
      x= x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key1<y->key1){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
void ins_order(struct Node1 *u){
  if(u==NIL)return ;
  ins_order(u->left);
  printf("%d ",u->key1);
  ins_order(u->right);
}
void pri_order(struct Node1 *u){
  if(u==NIL)return ;
  printf(" %d",u->key1);
  pri_order(u->left);
  pri_order(u->right);
}