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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node ROOT;
void insert(int);
void inorder(Node);
void preorder(Node);

int N;

int main(){
  int i,x;
  char com[20];
  scanf("%d",&N);

  for ( i = 0; i < N; i++ ){
    scanf("%s", com);
      if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(ROOT);
      printf("\n");
      preorder(ROOT);
      printf("\n");
  }
}

  return 0;
}


void insert(int z){
  Node T;
  Node y;
  Node x;
  T = malloc(sizeof(Node)*1);
  y = NIL;
  x = ROOT;
  T->key = z;
  T->left = NIL;
  T->right = NIL;
  while(x != NIL){
    y = x;
    if(T->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  T->parent = y;

  if(y == NIL){
    ROOT = T; // Tree is empty
  }
  else if(T->key < y->key){
    y->left = T;
  }

  else{
    (y->right) = T;
  }
}

void inorder(Node n){

  if(n != NIL){
    inorder(n->left);
      printf(" %d\n",n->key);
      inorder(n->right);
  }
}

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