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

struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

struct Node *root, *nil;

void insert(int k){
  struct Node *y=nil, *x=root, *z;

  z = malloc(sizeof(struct Node));
  z->key=k;
  z->right=nil;
  z->left=nil;
  while(x!=nil){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==nil)root=z;
  else {
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(struct Node *n){
  if(n==nil)return;
  inorder(n->left);
  printf(" %d",n->key);
  inorder(n->right);
}

void preorder(struct Node *n){
  if(n==nil)return;
  printf(" %d",n->key);
  preorder(n->left);
  preorder(n->right);
}

int main(){
  int i, n, s;
  char c[10];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", c);
    if(strcmp(c, "insert")==0){
      scanf("%d", &s);
      insert(s);
    }
    else if(strcmp(c, "print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}