n = int(input())
deg = [0 for _ in range(n)]
edges = []
for e in range(n-1):
    a,b = map(int, input().split(" "))
    deg[a-1]+=1
    deg[b-1]+=1
    edges.append([a-1,b-1])
d3 = -1
for n,i in enumerate(deg):
    if i>=3:
        d3 = n
        break
if d3==-1:
    for i in range(n):
        print(i)
else:
    curr = deg[d3]
    c2 = 0
    for n,i in enumerate(edges):
        if d3 in i:
            print(c2)
            c2+=1
        else:
            print(curr)
            curr+=1
