#include<stdio.h>
#include<stdlib.h>
 #define MAX 500001
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node r;
 
void insert(int);
void inorder(Node);
void preorder(Node);
 
void insert(int k){
  Node y = NULL;
  Node x = r;
  Node z;
 
  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) r = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
 
}
 
void inorder(Node u){
    if(u->left != NULL) inorder(u->left);
    printf(" %d", u->key);
    if(u->right != NULL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NULL) preorder(u->left);
  if(u->right != NULL) preorder(u->right);
}
 
 
int main(){
  int i,j,n;
  int x[MAX];
  char com[MAX][7];
  Node t;
 
  scanf("%d", &n);
 
  for( i = 0, j = 0;i < n;i++){
    scanf("%s", com[i]);
    if(com[i][0] == 'i'){
      scanf("%d", &x[j]);
      j++;
    }
  }
   
  r= malloc(sizeof(struct node));
  t = malloc(sizeof(struct node));
  r->left = NULL;
  r->right = NULL;
  r->parent = NULL;
 
  t = r;
 
  for( i = 0,j = 0;i < n;i++){
    if(com[i][0] == 'i' && i == 0){
      r->key = x[j];
      j++;
    }
    else if(com[i][0] == 'i'){
      insert(x[j]);
      j++;
    }
    else {
      inorder(t);
      printf("\n");
      preorder(t);
      printf("\n");
    }
  }
 
  free(r);
  return 0;
}