from collections import *
n = int(input())
g = defaultdict(set)

l = []
ans = [-1 for i in range(n-1)]
camein = [set() for i in range(n + 10)]
if n == 2:
    print(0)
    exit()
elif n == 3:
    print(0,1)
    exit()
done = 1
curr = 0
for i in range(n - 1):
    a,b = [int(i) for i in input().split()]
    g[a].add(b)
    g[b].add(a)
    
    camein[a].add(i)
    camein[b].add(i)
    if done:
        if len(camein[a]) == 3:
            for k in camein[a]:
                ans[k] = curr
                curr += 1
                if curr == 3:break
            done = 0
        elif len(camein[b]) == 3:
            for k in camein[b]:
                ans[k] = curr
                curr += 1
                if curr == 3:break
            done = 0

for i in range(n - 1):
    if ans[i] == -1:
        ans[i] = curr
        curr += 1
print(*ans[:-1],sep='\n')

