import sys
input = iter(sys.stdin.readlines()).__next__

import collections

n = int(input())
edges = collections.defaultdict(set)
e_labels = [None]*(n-1)

for i in range(n-1):
    u, v = map(int, input().split())
    edges[u].add(i)
    edges[v].add(i)

    if len(edges[v]) == 3:
        u = v

    if len(edges[u]) == 3:
        for k, j in enumerate(edges[u]):
            e_labels[j] = k
        k = 3
        for j in range(n-1):
            if e_labels[j] == None:
                e_labels[j] = k
                k += 1
        break
else:
    e_labels = list(range(n-1))

print(*e_labels, sep='\n')
