n = int(input())
graph = {}

maxi = 1
for i in range(n-1):
    u, v = map(int, input().split())
    if u not in graph:
        graph[u] = {i}
    else:
        graph[u].add(i)
    if v not in graph:
        graph[v] = {i}
    else:
        graph[v].add(i)
    if len(graph[u]) >= 3:
        maxi = u
        break
    if len(graph[v]) >= 3:
        maxi = v
        break
w = 0
t = n-2
temp = []
for j in range(n-1):
    if j in graph[maxi]:
        temp.append(str(w))
        w += 1
    else:
        temp.append(str(t))
        t -= 1
print('\n'.join(temp))