import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
n=int(input())
adj=[[] for _ in range(n+1)]
for edgeNo in range(n-1):
    u,v=[int(x) for x in input().split()]
    adj[u].append([v,edgeNo])
    adj[v].append([u,edgeNo])
#if there are at least 3 leaves, put 0,1,2 on edges connected to them

allLeafEdges=set()

for node in range(1,n+1):
    if len(adj[node])==1: #node is leaf
        allLeafEdges.add(adj[node][0][1])
allLeafEdges=list(allLeafEdges)
ans=[-1 for __ in range(n-1)]
if len(allLeafEdges)>=3:
    ans[allLeafEdges[0]]=0
    ans[allLeafEdges[1]]=1
    ans[allLeafEdges[2]]=2
    
    idx=0
    for i in range(3,n-1):
        while (idx<n-1 and ans[idx]!=-1):
            idx+=1
        ans[idx]=i
else:
    ans=list(range(n-1))
print('\n'.join([str(x) for x in ans]))