n = int(input())
 
G = [0]*n
V = []
for i in range(n-1):
    x,y = [int(x)-1 for x in input().split()]
    G[x] += 1
    G[y] += 1
    V.append((x,y))
 
good = -1
for i in range(n):
    if G[i] > 2:
        good = i
        break
if good == -1:
    for i in range(n-1):
        print(i)
else:
    deg = G[good]-1
    bad = 0
    for i in range(n-1):
        if good in V[i]:
            print(deg)
            deg -= 1
        else:
            print(G[good]+bad)
            bad += 1