n = int(input())
edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
ans = {e: -1 for e in edges}
gs = [[] for _ in range(n + 1)]
for u, v in edges:
    gs[u].append(v)
    gs[v].append(u)

g = max(range(1, n + 1), key=lambda x: len(gs[x]))

cnt = 0
for v in gs[g]:
    uv = g, v
    if uv not in ans:
        uv = v, g
    ans[uv] = cnt
    cnt += 1

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