module DoublyChainedTree = struct
  let nil = -1

  type t = {
    mutable parent : int;
    mutable child : int;
    mutable bro : int;
    mutable depth : int;
  }

  let make () = { parent = nil; child = nil; bro = nil; depth = nil }
end

module T = DoublyChainedTree

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> T.make ()) in
  let rec read_tree i =
    if i < n then begin
      let id, k = Scanf.scanf "%d %d " (fun id k -> id, k) in
      let rec read_node j left_child =
        if j < k then begin
          let c = Scanf.scanf "%d " (fun c -> c) in
          t.(c).T.parent <- id;
          if j = 0 then t.(id).T.child <- c else t.(left_child).T.bro <- c;
          read_node (j + 1) c
        end
      in
      read_node 0 0;
      read_tree (i + 1)
    end
  in
  read_tree 0;
  let rec search_root i =
    if i = n then T.nil
    else if t.(i).T.parent = T.nil then i
    else search_root (i + 1)
  in
  let root = search_root 0 in
  let rec set_depth i p =
    t.(i).T.depth <- p;
    if t.(i).T.bro <> T.nil then set_depth t.(i).T.bro p;
    if t.(i).T.child <> T.nil then set_depth t.(i).T.child (p + 1);
  in
  set_depth root 0;
  let print_node i =
    print_string "node "; print_int i; print_string ": parent = "; print_int t.(i).T.parent; print_string ", depth = "; print_int t.(i).T.depth;
    print_string (if t.(i).T.parent = T.nil then ", root, " else if t.(i).T.child = T.nil then ", leaf, " else ", internal node, ");
    print_string "[";
    let rec print_children c =
      if c <> T.nil then begin
        if c <> t.(i).T.child then print_string ", ";
        print_int c;
        print_children t.(c).T.bro
      end
    in
    print_children t.(i).T.child;
    print_endline "]"
  in
  let rec print i =
    if i < n then (print_node i; print (i + 1))
  in
  print 0