#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node{
  int key;
  struct Node *r, *l, *p;
};
void insert(int f);
void inorder(struct Node *v);
void preorder(struct Node *w);
struct Node *root, *NIL;

int main(){
  char C[10];
  int n, i, a;
  scanf("%d", &n);
  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){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
  }

void insert(int f){
  struct Node *x = root;
  struct Node *y = NIL;
  struct Node *z;
  z = ((struct Node *)malloc(sizeof(struct Node)));
  z->key = f;
  z->l = NIL;
  z->r = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else {
      x = x->r;
    }
  }
  z->p = y;
  if(y == NIL){
    root = z;
  }
  else {
    if(z->key < y->key){
      y->l = z;
    } else {
      y->r = z;
    }
  }
}

void inorder(struct Node *v){
  if(v == NIL) return;
  inorder(v->l);
  printf(" %d", v->key);
  inorder(v->r);
  }

  void preorder(struct Node *w){
    if(w == NIL) return;
    printf(" %d", w->key);
    preorder(w->l);
    preorder(w->r);
}

