n = int(input())
freqs = [0 for _ in range(n+1)]
uv = []
for _ in range(n-1):
    u, v = map(int, input().split())
    freqs[u]+=1
    freqs[v]+=1
    uv.append((u,v))

mn = 0
mx = n-2
for u, v in uv:
    if freqs[u] == 1 or freqs[v] == 1:
        print(mn)
        mn+=1
    else:
        print(mx)
        mx-=1
