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 res3:
        res3 = False
        res[d[k][0]] = 0
        res[d[k][1]] = 1
        res[d[k][2]] = 2
        num += 3
        

n = getInt()
res3 = True
res = []
d = {}
num = n-2
for i in range(n-1):
    u, v = getVars()
    res.append(num)
    num -= 1
    foo(u, i)
    foo(v, i)
for i in range(n-1):
    print(res[i])
    
