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

#define N 500001
#define NIL NULL
struct Binary{
  int key;
  struct Binary *right;
  struct Binary *left;
  struct Binary *p;
};

void insert(int);
void inordertree(struct Binary *);
void preordertree(struct Binary *);

int n;
struct Binary *root;

int main(){
  int i,a;
  char c[20];
  char dummy;
  scanf("%d",&n);
  scanf("%c", &dummy);
  for(i=0 ; i<n ; i++){
    scanf("%s",c);
     
    if(strcmp(c,"insert")==0){
      scanf("%d",&a);
      insert(a);
    }
    else if(strcmp(c,"print")==0){    
      inordertree(root);
      printf("\n");
      preordertree(root);
      printf("\n");
    }
  }
  
  return 0;
}

void insert(int a){
  struct Binary *y=NIL,*x=root,*z;
  z = malloc(sizeof(struct Binary));
  z->left = NIL;
  z ->right = NIL;
  z->key = a;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inordertree(struct Binary *a){
  if(a!=NIL){
    inordertree(a->left);
    printf(" %d",a->key);
    inordertree(a->right);
  }
}

void preordertree(struct Binary *a){
  if(a!=NIL){
    printf(" %d",a->key);
    preordertree(a->left);
    preordertree(a->right);
  }
}

