from sys import stdin
n=int(input())
e=[]
ad=[[] for _ in range(n)]
for _ in range(n-1):
    
    a,b=map(int,stdin.readline().split())
    a-=1
    b-=1
    e.append((a,b))
    ad[a].append(b)
    ad[b].append(a)
three={}
for x in range(n):
    if len(ad[x])>2:
        for i in range(3):
            three[(x,ad[x][i])]=three[(ad[x][i],x)]=i
        break
i=n-2
for x in e:
    if x in three:
        print(three[x])
    else:
        print(i)
        i-=1