//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);

line.shift();

tree = {};

function make_node(n) {
  var node;
  if (tree.hasOwnProperty(n)) return tree[n];
  node = {'parent': -1, 'depth': null, 'type': null, 'children': null};
  tree[n] = node;
  return node;
}

for (i in line) {
  ary = line[i].split(' ');
  node_id = ary.shift();
  node = make_node(node_id);
  ary.shift();
  node.children = ary;
  if (ary.length === 0) node.type = 'leaf';
  else node.type = 'internal node';
  for (j in ary) {
    child = make_node(ary[j]);
    child.parent = node_id;
  }
}

for (i in tree)
  if (tree[i].parent === -1) root_id = i;
root = tree[root_id];
root.type = 'root';

function set_depth(node, depth) {
  var children;
  node.depth = depth;
  children = node.children;
  for (i in children)
    set_depth(tree[children[i]], depth + 1);
}

set_depth(root, 0);

keys = Object.keys(tree);
keys.sort(function (a, b) { return a - b; });

for (i in keys) {
  console.log('node %s: parent = %s, depth = %d, %s, [%s]',
    i, tree[i].parent, tree[i].depth, tree[i].type,
    tree[i].children.join(', '));
}