import sys
 
def input():
    return sys.stdin.readline()
 
def iinput():
    return int(input())
 
def rinput():
    return input().split()
 
def rlinput():
    return [int(i) for i in input().split()]
 
def main():
    #q = rlinput() rinput() iinput() input()
    n = iinput()
    w = []
    q = [[] for i in range(n)]
    for i in range(n - 1):
        u, v = rlinput()
        q[u - 1].append(i)
        q[v - 1].append(i)   
    for i in range(n):
        if len(q[i]) == 1:
            w.append(i)
    if len(w) < 3:
        for i in range(n - 1):
            print(i)
    else:
        o = 3
        for i in range(n - 1):
            if i == q[w[0]][0]:
                print(0)
            elif i == q[w[1]][0]:
                print(1)
            elif i == q[w[2]][0]:
                print(2)
            else:
                print(o)
                o += 1
for i in range(1):
    main()