n = int(input())
inputEdges = []
adjList = [[] for i in range(0,n+1)]
for i  in range(0,n-1):
    edge = list(map(lambda x: int(x), input().split()))
    inputEdges.append(edge)
    adjList[edge[0]].append(edge[1])
    adjList[edge[1]].append(edge[0])

isLinear = True
junction = 0
for i in range(1,n+1):
    if len(adjList[i]) >= 3:
        junction = i
        isLinear = False
        break

high=n-2
low=0
if(isLinear):
    for i in range(0,n-1):
        print(i)
else:
    for e in inputEdges:
        if e[0]==junction or e[1]==junction:
            print(low)
            low+=1
        else:
            print(high)
            high-=1


