#include<stdio.h>
#include<stdlib.h>
#define NIL -1

typedef struct node{

  int key;  
  struct node *p;
  struct node *r;
  struct node *l;
}Node; 

void insert(int);
void nodegene(Node *, int);
void print();
void in_p(Node *);
void pre_p(Node *);
 
Node *root = NULL;
int main(){

  char str[10];
  int i,n,m,l;
  Node *node;

  scanf("%d", &n);

  //scanf("%d", &l);
  //nodegene( root,l);

  for( i = 0; i < n; i++){

    scanf("%s", str);

    switch(str[0]){
    case 'i':
      scanf("%d",&m);
      insert(m);
      break;

    case 'p':
      print();
      break;
    }
  }
return 0;
}

void nodegene(Node *n,int num){
  n -> key = num;
  n -> p = NULL;
  n -> r = NULL;  
  n -> l = NULL;
}


void insert(int n){
 
  Node *p = malloc(sizeof(Node));
  Node *search;

  nodegene( p, n);

  if(root == NULL){
    root = p;
    return;
  }

  search = root;

  while (1) {
    if (p -> key < search -> key) {
      if (search -> l == NULL) {
	search -> l = p;
	break;
      } 
      else {
	search = search -> l;
      }
    } 
    else {
      if (search -> r == NULL) {
	search -> r = p;
	break;
      } 
      else {
	search = search -> r;
      }
    }
  }
  search = p;
 
}


void in_p(Node *n){
  
  if(n != NULL){
    in_p(root -> l);
    printf(" %d", n -> key);
    in_p(root -> r);
  }
}

void pre_p(Node *n){
  
  if(n != NULL){  
    printf(" %d", n -> key);
    pre_p(root -> l);
    pre_p(root -> r);
  }
}

void print(){

  in_p( root);
  printf("\n");  
  pre_p( root);
  printf("\n");
}