import sys
input = sys.stdin.readline
def getInt(): return int(input())
def getVars(): return map(int, input().split())
def getList(): return list(map(int, input().split()))
def getStr(): return input().strip()
## -------------------------------

def foo(k, ii):
    global d, res3, res, num
    if k not in d:
        d[k] = []
    d[k].append(ii)
    if len(d[k]) == 3 and len(res3) == 0:
        res3 = d[k].copy()
        

n = getInt()
res3 = []

d = {}
num = n-2
for i in range(n-1):
    u, v = getVars()
    foo(u, i)
    foo(v, i)

num = n-2
num3 = 0
for i in range(n-1):
    if i in res3:
        print(num3)
        num3+=1
    else:
        print(num)
        num -= 1
