from collections import *
n = int(input())
g = defaultdict(set)
l = []
for i in range(n - 1):
    a,b = [int(i) for i in input().split()]
    l.append([a,b])
    g[a].add(b)
    g[b].add(a)

if n == 2:
    print(0)
elif n == 3:
    print(1,0,sep='\n')
else:
    ans = [-1 for i in range(n)]
    curr = 0
    all = set()
    for i in g:
        all |= g[i]
    
    for i in g:
        if len(g[i]) > 1 and i in all:
            for k in range(n - 1):
                if i in l[k]:
                    ans[k] = curr
                    curr += 1
                if curr == 3:
                    break
            break
    for i in range(n-1):
        if ans[i] == -1:
            ans[i] = curr
            curr += 1
    print(*ans[:-1],sep = '\n')