let nil = -1

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

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

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1)
  in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1);
  in
  doit (root 0) 0

let print_tree t =
  let print i =
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, " else if t.(i).child = nil then ", leaf, " else ", internal node, ");
    print_string "[";
    let rec print_children c =
      if c <> nil then begin
        if c <> t.(i).child then print_string ", ";
        print_int c;
        print_children t.(c).bro
      end
    in
    print_children t.(i).child;
    Printf.printf "]\n";
  in
  Array.iteri (fun i _ -> print i) t

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  let rec read 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 i -> i) in
          t.(c).parent <- id;
          if j = 0 then t.(id).child <- c else t.(left_child).bro <- c;
          read_node (j + 1) c
        end
      in
      read_node 0 0;
      read (i + 1)
    end
  in
  read 0;
  set_depth t n;
  print_tree t