def main():
    n = int(input())
    turns = []
    dct = dict()
    to_spec = n
    for i in range(n - 1):
        a, b = map(int, input().split())
        turns.append((a, b))
        if a in dct:
            if dct[a] == 1:
                dct[a] += 1
                to_spec -= 1
        else:
            dct[a] = 1
        if b in dct:
            if dct[b] == 1:
                dct[b] += 1
                to_spec -= 1
        else:
            dct[b] = 1

    to_add1 = 0
    line = ""
    for i in turns:
        if dct[i[0]] == 1 or dct[i[1]] == 1:
            line += str(to_add1) + "\n"
            to_add1 += 1
        else:
            line += str(to_spec) + "\n"
            to_spec += 1
    print(line)


if __name__ == "__main__":
    t = 1
    for i in range(t):
        main()
