from collections import defaultdict
N = int(input())
arr = [[] for i in range(N+1)]
Dict = {}
List = []
for _ in range(N-1):
    i,j=map(int,input().split())
    arr[i].append(j)
    arr[j].append(i)
    Dict[str(i)+" "+str(j)] = -1
    List.append(str(i)+" "+str(j))
count = 0
stack = []
visited = [0]*(N+1)
stack.append(1)
while(stack):
    A = stack.pop()
    visited[A] = 1
    flag = 0
    for i in arr[A]:
        if (visited[i]==0):
            stack.append(i)
            visited[i] = 1
            flag = 1
    if (flag==0):
        if (str(A)+" "+str(arr[A][0]) in Dict):
            Dict[str(A)+" "+str(arr[A][0])] = count
        else:
            Dict[str(arr[A][0])+" "+str(A)] = count
        # print(str(A)+" "+str(arr[A][0]),count)
        count+=1

for i in Dict:
    # print(i)
    if (Dict[i]==-1):
        Dict[i] = count
        count+=1
for i in List:
    print(Dict[i])