#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,i;
  int k;
  char t[5];

  scanf("%d",&n);
  
  for(i=0 ; i<n ; i++){
    scanf("%s",t);
    if(t[0]== 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    if(t[0]=='i'){
    scanf("%d",&k);
    insert(k);
    }
  }

  return 0;
}


void insert(int k){
  Node z;
  Node y = NULL;
  Node x = root;
  z = malloc(sizeof(struct node));
  z->key = k;
  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 inorder(Node T){
  if(T != NULL){
    inorder(T->left);
    printf(" %d",T->key);
    inorder(T->right);
  }
}


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