#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MAX_W = 100000;

struct Node {
    int parent = -1;
    int left = -1;
    int right = -1;

    Node() : parent(-1), left(-1), right(-1) {}
    Node(int p, int l, int r) : parent(p), left(l), right(r) {}
    Node(Node& n) {
        parent = n.parent;
        left = n.left;
        right = n.right;
    }
};

int root(vector<Node>& nodes) {
    int i = 0;
    while (nodes[i].parent != -1) { i = nodes[i].parent; }
    return i;
}

void sibling(vector<Node>& nodes, vi& siblings, int i) {
    bool is_left = (nodes[i].left != -1);
    bool is_right = (nodes[i].right != -1);

    if (is_left) { sibling(nodes, siblings, nodes[i].left); }
    if (is_right) { sibling(nodes, siblings, nodes[i].right); }
    if (is_left && is_right) {
        siblings[nodes[i].left] = nodes[i].right;
        siblings[nodes[i].right] = nodes[i].left;
    }
}

void degree(vector<Node>& nodes, vi& degrees, int i) {
    int sum = 0;
    if (nodes[i].left != -1) {
        ++sum;
        degree(nodes, degrees, nodes[i].left);
    }
    if (nodes[i].right != -1) {
        ++sum;
        degree(nodes, degrees, nodes[i].right);
    }
    degrees[i] = sum;
}

void depth(vector<Node>& nodes, vi& depths, int i, int d) {
    depths[i] = d;
    if (nodes[i].left != -1) { depth(nodes, depths, nodes[i].left, d + 1); }
    if (nodes[i].right != -1) { depth(nodes, depths, nodes[i].right, d + 1); }
}

void height(vector<Node>& nodes, vi& heights, int i) {
    int t = 0;

    if (nodes[i].left != -1) {
        height(nodes, heights, nodes[i].left);
        t = max(t, heights[nodes[i].left] + 1);
    }
    if (nodes[i].right != -1) {
        height(nodes, heights, nodes[i].right);
        t = max(t, heights[nodes[i].right] + 1);
    }
    heights[i] = t;
}

void state(vector<Node>& nodes, vector<string>& states, int i) {
    bool is_left = (nodes[i].left != -1);
    bool is_right = (nodes[i].right != -1);

    if (nodes[i].parent == -1) {
        states[i] = "root";
    } else if (is_right || is_left) {
        states[i] = "internal node";
    } else {
        states[i] = "leaf";
    }

    if (is_left) { state(nodes, states, nodes[i].left); }
    if (is_right) { state(nodes, states, nodes[i].right); }
}

int main() {
    int n;
    cin >> n;
    vector<Node> nodes(n);

    rep(i, 0, n) {
        int id, left, right;
        cin >> id >> left >> right;

        nodes[id].left = left;
        nodes[id].right = right;

        if (left != -1) { nodes[left].parent = id; }
        if (right != -1) { nodes[right].parent = id; }
    }

    vi siblings(n, -1), degrees(n, 0), depths(n, 0), heights(n, 0);
    vector<string> states(n);

    int r = root(nodes);
    sibling(nodes, siblings, r);
    degree(nodes, degrees, r);
    depth(nodes, depths, r, 0);
    height(nodes, heights, r);
    state(nodes, states, r);

    rep(i, 0, n) {
        cout << "node " << i << ": parent = " << nodes[i].parent;
        cout << ", sibling = " << siblings[i];
        cout << ", degree = " << degrees[i];
        cout << ", depth = " << depths[i];
        cout << ", height = " << heights[i];
        cout << ", " << states[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3160