n = int(input())
graph = [[] for _ in range(n)]
edges = []
d = dict()
for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v)
    graph[v].append(u)
    edges.append((u, v))
    d[(u, v)] = i
    d[(v, u)] = i

ans = [None] * (n - 1)
for u in range(n):
    if len(graph[u]) >= 3:
        v1 = graph[u][0]
        v2 = graph[u][1]
        v3 = graph[u][2]
        ans[d[(u, v1)]] = 0
        ans[d[(u, v2)]] = 1
        ans[d[(u, v3)]] = 2
        break

c = 3
for i in range(n - 1):
    if ans[i] is None:
        ans[i] = c % (n - 1)
        c += 1
print('\n'.join(map(str, ans)))