import sys
import collections
input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N - 1)]
    V = [[] for j in range(N)]
    for i, (a, b) in enumerate(AB):
        V[a - 1].append([b - 1, i])
        V[b - 1].append([a - 1, i])


    f = False
    ans = [-1] * (N - 1)
    for v in V:
        if len(v) >= 3:
            f = True
            for i in range(3):
                ans[v[i][1]] = i
            break


    cnt = 0
    if f:
        cnt = 3

    for a in ans:
        if a == -1:
            print(cnt)
            cnt += 1
        else:
            print(a)




    

if __name__ == '__main__':
    main()


