if __name__ == "__main__":
    n = int(input())
    l = [0 for i in range(n+1)]
    deg3 = -1
    edges = []
    for i in range(n-1):
        u,v = map(int, input().split())
        edges.append([u,v])
        l[u]+=1
        l[v]+=1
        if deg3 == -1:
            if l[u] == 3:
                deg3 = u
            if l[v] == 3:
                deg3 = v
    #tree has a node with degree more than 2
    if deg3 != -1:
        nC = 3
        deg3C = 0
        for i in edges:
            u,v = i
            if (u == deg3 or v == deg3) and deg3C != 3:
                print(deg3C)
                deg3C+=1
            else:
                print(nC)
                nC+=1
    else:
        nC = 0
        for i in edges:
            print(nC)
            nC+=1
        
            
