def solution():
    from sys import stdout, stdin
    _input, _print = stdin.readline, stdout.write
    _list, _range, _str, _len, _int = list, range, str, len, int
    from collections import defaultdict
    n = _int(_input())
    edge = {}
    counter = defaultdict(_int)
    ans = [-1]*(n-1)
    for i in _range(n-1):
        u, v = [_int(i) for i in _input().split()]
        edge[i] = (u, v)
        counter[u] += 1
        counter[v] += 1
    current = 1
    k = 1
    last = -1
    while ans.count(-1) > 0:
        for i in _range(n-1):
            l, r = edge[i]
            if counter[r] == k:
                ans[i] = current
                last = i
                current += 1
        for i in counter.keys():
            if counter[i] == k:
                counter[i] -= k
        k += 1
    ans[last] = 0
    for i in ans:
        print(i)
solution()
