n = int(input())
t = []
yy = False
hh = 0
C = [0]*(n+1)
for i in range(n-1):
    a,b = map(int, input().split())
    t.append((a,b))
    C[a] += 1
    C[b] += 1
    if not yy:
        if C[a] > 2:
            hh = a
            yy = True
        if C[b] > 2:
            hh = b
            yy = True

if not yy:
    for i in range(0,n-1):
        print(i)
else:
    a1 = 0
    a2 = 3
    for i in range(n-1):
        if t[i][0] != hh and t[i][1] != hh:
            print(a2)
            a2 += 1
        else:
            print(a1)
            a1 += 1
            if a1>2:
                hh = -1


