#include <stdio.h>
#include <stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
 
typedef struct node * Node;
 
Node root;
void insert(int);
 
void inorder (Node);
void preorder (Node);
 
 
int main(){
 
  int n,num,i;
  char command[10];
 
  scanf("%d",&n);
 
  root = NULL;
  for(i = 0 ; i < n ; i++){
 
    scanf("%s",command);
 
    if(command[0] == 'i'){//insert
      scanf("%d",&num);
      insert(num);
    }
 
    else if(command[0] == 'p'){//print
      inorder(root);
      printf("\n");
 
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}
 
 
void insert( int z){
 
  Node y = NULL;
  Node x = root;
  Node k;
 
  k = malloc(sizeof(struct node));
 
  k -> key = z;
  k -> left = NULL;
  k -> right = NULL;
 
 
  while(x != NULL){
    y = x;
    if(k -> key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
    k->parent = y;
    if(y == NULL)root = k;
    else if(k->key < y->key)y->left = k;
    else y->right = k;
}
 
 
void inorder (Node o){
  if(o->left != NULL)inorder(o->left);
  printf(" %d",o->key);
 
  if(o->right != NULL)inorder(o->right);
}
 
 
 
 
void preorder(Node o){
  printf(" %d",o->key);
 
  if(o->left != NULL)preorder(o->left);
  if(o->right != NULL)preorder(o->right);
}

