from collections import defaultdict
N = int(input())
arr = defaultdict(list)
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
for i in arr:
    if (len(arr[i])==1):
        if (str(i)+" "+str(arr[i][0]) in Dict):
            Dict[str(i+1)+" "+str(arr[i][0])] = count
        else:
            Dict[str(arr[i][0])+" "+str(i)] = count
        count+=1
for i in Dict:
    if (Dict[i]==-1):
        Dict[i] = count
        count+=1
for i in List:
    print(Dict[i])