from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations


# Fast IO utilities
raw_input = stdin.readline
pr = stdout.write


def in_arr():
    return map(int,raw_input().split())


def pr_num(n):
    stdout.write(str(n)+'\n')


def pr_arr(arr):
    for i in arr:
        stdout.write(str(i)+' ')
    stdout.write('\n')

# commment out below line for python version 3.0+
range = xrange

# main code

for t in range(1):
    n=input()
    d=Counter()
    arr=[]
    for i in range(n-1):
        u,v=in_arr()
        d[u]+=1
        d[v]+=1
        arr.append((u,v))
    arr1=sorted(arr,key=lambda x:(d[x[0]]+d[x[1]]),reverse=True)
    d1=Counter()
    curr=0
    for i in arr1:
        d1[i]=curr
        curr+=1
    for i in arr:
        pr_num(d1[i])
    
