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

typedef struct node{
  int key;
  struct node *parent,*left,*right;
}Node;

Node *root,*NIL;

void Insert(int);
void Inorder(Node *);
void Preorder(Node *);

int main(){
  int m,i,k;
  char com[20];

  scanf("%d",&m);

  for(i=0; i<m; i++){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&k);
      Insert(k);
    }
    else if(com[0] == 'p'){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

    return 0;
}
  
void Insert(int k){
  Node *y = NIL;            
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(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;
}

void Inorder(Node *r){
  if(r != NIL){
    Inorder(r->left);
    printf(" %d",r->key);
    Inorder(r->right);
  }
}

void Preorder(Node *r){
  if(r != NIL){
    printf(" %d",r->key);
    Preorder(r->left);
    Preorder(r->right);
  }
}