import math
import sys

        
n=int(input())
g=[[] for i in range(n)]
inp=[]

for i in range(n-1):
    u,v=map(int,input().split())
    v-=1;u-=1
    inp.append([u,v])
    g[u].append(v)
    g[v].append(u)

right=n-2;left=0

for i in range(n-1):
    if len(g[inp[i][0]])==1 or len(g[inp[i][1]])==1:
        print(left)
        left+=1
    else:
        print(right)
        right-=1