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

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

 Node root;

void insert(int key){
  Node x = root;
  Node y = NULL;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = key;
  z->left = NULL;
  z->right = NULL;

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

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

void inorderTreeWalk(Node x){
  if(x != NULL){
    inorderTreeWalk(x->left);
    printf(" %d",x->key);
    inorderTreeWalk(x->right);
  }
}

void preorderTreeWalk(Node x){
  if(x == NULL){
    return;
  }
  printf(" %d",x->key);
  preorderTreeWalk(x->left);
  preorderTreeWalk(x->right);
}

void printer(){
  inorderTreeWalk(root);
  printf("\n");
  preorderTreeWalk(root);
  printf("\n");
}

int main(){
  int i, n, key;
  char command[10];

  scanf("%d ",&n);
  for(i=0; i<n; i++){
    scanf("%s ",command);
    if(!strcmp(command, "insert")){
      scanf("%d ",&key);
      insert(key);
    }
    else if(!strcmp(command, "print")){
      printer();
    }
  }

  return 0;
}

