n = int(input())
g = [[] for _ in range(n)]
ans = [-1] * (n - 1)
for _ in range(n - 1):
    u, v = map(int, input().split())
    g[u - 1].append(_)
    g[v - 1].append(_)
cnt = 3
for i in range(n):
    if len(g[i]) >= 3:
        for j in range(3):
            ans[g[i][j]] = j
        break
else:
    cnt = 0
for i in range(n - 1):
    if ans[i] == -1:
        ans[i] = cnt
        cnt += 1
for x in ans:
    print(x)
