n = int(input())
adj = [ [] for _ in range(n) ]
edg = []
for i in range(0,n-1):
    V = list( map(int,input().split()) )
    u,v = V[0]-1,V[1]-1
    adj[u].append(v)
    adj[v].append(u)
    edg.append( (u,v) )
ans = []
for i in range(0,n-1):
    ans.append(-1)
cnt = 0
for i in range(0,n-1):
    if ( len(adj[ edg[i][0] ])==1 or len(adj[ edg[i][1] ])==1 ) and cnt<3 :
        ans[i] = cnt
        cnt += 1
for i in range(0,n-1):
    if ans[i]==-1:
        ans[i] = cnt
        cnt += 1
for i in range(0,n-1):
    print(ans[i])