from collections import defaultdict
N = int(input())
arr = [0]*(N+1)
Dict = {}
List = []
for _ in range(N-1):
    i,j=map(int,input().split())
    List.append([i,j])
    arr[i]+=1
    arr[j]+=1
count = 0
ans = [-1]*(N-1)
for i in range(N-1):
    if (arr[List[i][0]]==1 or arr[List[i][1]]==1):
        ans[i] = count
        count+=1
for i in range(N-1):
    if (ans[i-1]==-1):
        ans[i-1] = count
        count+=1
for i in range(N-1):
    print(ans[i])