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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
int n;

void insert(int i, int l, int r){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = i;
  z->left->key = l;
  z->right->key = r;
  printf("ID:%d Left_child:%d Right_child:%d ",z->key, z->left->key,z->right->key);

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;
  printf("Parent_id:%d\n",z->parent->key );

  if (y == NIL) {
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}
int main() {
  int id;
  int left;
  int right;
  int i;

  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    scanf("%d",&id);
    scanf("%d",&left);
    scanf("%d",&right );
    insert(id, left, right);
  }

  return 0;
}

