import sys
input = sys.stdin.readline
n = int(input())
sz = [0 for i in range(n+1)]
ans = [-1 for i in range(n+1)]
graph =[[] for i in range(n+1)]
for i in range(n-1):
    u, v = map(int, input().split())
    sz[u] += 1
    sz[v] += 1
    graph[u].append([v, i])
    graph[v].append([u, i])
cur = 0
for i in range(1, n+1):
    if (sz[i] >= 3):
        ans[graph[i][0][1]] = 0
        ans[graph[i][1][1]] = 1
        ans[graph[i][2][1]] = 2
        cur = 3
        break
for i in range(n-1):
    if ans[i] == -1:
        ans[i] = cur
        cur += 1
for i in range(n-1):
    print(ans[i])