#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 500000
 
struct Node {
  int key;
  struct Node *parent,*left,*right;
};

struct Node *NIL,*root;

void inorder(struct Node *);
void preorder(struct Node *);
void insert(int);

int main(){

  int i,n,x;
  char command[N][10];


  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command[i]);
    if(strcmp(command[i],"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    if(strcmp(command[i],"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }  
  return 0;
}

    
void inorder(struct Node *x){
  if(x==NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}


void preorder(struct Node *x){
  if(x==NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}
 



void insert(int k){

  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else 
      x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else y->right=z;
}
 