import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
d = {i:[] for i in range(1,n+1)}
a = []
for i in range(n-1):
    u,v = list(map(int,input().split()))
    d[u].append(v)
    d[v].append(u)
    a.append((u,v))
c = 0
# print(d)
d1 = {}
for i,j in a:
    if len(d[i])==1 or len(d[j])==1:
        d1[(i,j)] = c
        c+=1
    if c == 3:
        break
for i,j in a:
    if (i,j) not in d1:
        print(c)
        c+=1
    else:
        print(d1[(i,j)])