from collections import defaultdict
n = int(input())

d = defaultdict(list)


for i in range(n-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)


m = (0, 0)
for x, y in d.items():
    m = max(m, (len(y), x))


c = 0
x = [-1]*(n+10)
for i in d[m[1]]:
    x[i-1] = c
    c += 1

for i in range(1, n):
    if x[i] == -1:
        x[i] = c
        c += 1

for i in range(1, n):
    print(x[i])
