from sys import stdin
n=int(input())
node=[[]for i in range(n+1)]
x=[]
m=dict()
for i in range(n-1):
    a,b=map(int,stdin.readline().split())
    x.append([a,b])
    m[a,b]=m[b,a]=-1
    node[a].append(b)
    node[b].append(a)
num=3
for i in range(1,n+1):
    if len(node[i])>=3:
        for i2 in range(3):
            m[node[i][i2],i]=m[i,node[i][i2]]=i2
        break
    if i==n:
        num=0
for i in range(n-1):
    if m[x[i][0],x[i][1]]>=0: print(m[x[i][0],x[i][1]])
    else:
        print(num)
        num+=1