from collections import defaultdict
n = int(input().strip())
p = defaultdict(int)
tt = [0] * ((n-1)*2)
for i in range(n-1):
    x, y = map(int, input().strip().split())
    tt[i*2+0] = x
    tt[i*2+1] = y
    p[x] += 1
    p[y] += 1



cnt = 0

ans = [-1] * (n-1)

for i in range((n-1)):
    if p[tt[i*2+0]] == 1 or p[tt[i*2+1]] == 1:
        ans[i] = cnt
        cnt += 1

for i in range((n-1)):
    if ans[i] != -1:
        print(ans[i])
    else:
        print(cnt)
        cnt += 1
