from collections import Counter,OrderedDict
from sys import stdin
n = int(stdin.readline())
dct = Counter()
dct1 = OrderedDict()
for _ in range(n-1):
    x = tuple(map(int,stdin.readline().split()))
    dct1[x] = -1
    dct[x[0]]+=1
    dct[x[1]]+=1
co = 0
for r in dct:
    if dct[r] >= 3:
        for x in dct1:
            if x[0] == r or x[1] == r:
                dct1[x] = co
                co += 1
        break
for r in dct1.keys():
    if dct1[r] == -1:
        dct1[r] = co
        co += 1
for k in dct1.values():
    print(k)