n = int(input())
cc, ls = [0]*(n+1), []
for _ in range(n-1):
    a, b = map(int, input().split())
    ls.append((a, b))
    cc[a] += 1; cc[b] += 1

if n == 2: print(0); exit()

r = 0
for k, v in enumerate(cc):
    if v >= 3: r = k; break

idx = 3 if r > 0 else 0
rcc, res = 0, []
for a, b in ls:
    if rcc < 3 and (a == r or b == r):
        res.append(rcc)
        rcc += 1
    else:
        res.append(idx)
        idx += 1

for rs in res: print(rs)


