let nil = -1

type node = {
  mutable parent : int;
  mutable left : int;
  mutable right : int;
  mutable depth : int;
  mutable height : int;
}

let make () = {
  parent = nil;
  left = nil;
  right = nil;
  depth = nil;
  height = nil
}

let search_root t n =
  let rec doit i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else doit (i + 1)
  in doit 0

let set_depth t n =
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).left <> nil then doit t.(i).left (d + 1);
    if t.(i).right <> nil then doit t.(i).right (d + 1);
  in doit (search_root t n) 0

let set_height t n =
  let rec doit i =
    let hl = ref 0 in
    let hr = ref 0 in
    if t.(i).left <> nil then (doit t.(i).left; hl := t.(t.(i).left).height + 1);
    if t.(i).right <> nil then (doit t.(i).right; hr := t.(t.(i).right).height + 1);
    t.(i).height <- (max !hl !hr)
  in doit (search_root t n)

let print t =
  let sibling i =
    if t.(i).parent = nil then nil
    else if t.(t.(i).parent).left <> i && t.(t.(i).parent).left <> nil then t.(t.(i).parent).left
    else if t.(t.(i).parent).right <> i && t.(t.(i).parent).right <> nil then t.(t.(i).parent).right
    else nil
  in
  let degree i = 0 + (if t.(i).left <> nil then 1 else 0) + (if t.(i).right <> nil then 1 else 0) in
  let (p, q) = (print_string, print_int) in
  let print_node i =
    p "node "; q i;
    p ": parent = "; q t.(i).parent;
    p ", sibling = "; q (sibling i);
    p ", degree = "; q (degree i);
    p ", depth = "; q t.(i).depth;
    p ", height = "; q t.(i).height;
    p (if t.(i).parent = nil then ", root" else if t.(i).left = nil && t.(i).right = nil then ", leaf" else ", internal node");
    p "\n"
  in Array.iteri (fun i _ -> print_node i) t

let () =
  let n = read_int () in
  let t = Array.init n (fun _ -> make ()) in
  let rec read i =
    if i < n then begin
      let (id, l, r) = Scanf.scanf "%d %d %d\n" (fun id l r -> (id, l, r)) in
      t.(id).left <- l;
      t.(id).right <- r;
      if l <> nil then t.(l).parent <- id;
      if r <> nil then t.(r).parent <- id;
      read (i + 1)
    end in
  read 0;
  set_depth t n;
  set_height t n;
  print t