n = int(input())

c = [0] * 100005

q = []
for i in range(n-1):
    a,b = map(int, input().split())
    c[a] += 1
    c[b] += 1
    q.append([a,b])

x=0
y = n-2
res = []
for i in range(len(q)):
    if c[q[i][0]] == 1 or c[q[i][1]] == 1:
        res.append(x)
        x+=1
    else:
        res.append(y)
        y-=1
for i in res:
    print(i)
