import os
import sys
from atexit import register
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import defaultdict

n = int(input())
Edges = []#defaultdict(list)
Power = defaultdict(int)

for nn in range(n-1):
    u, v = map(int,input().split())
    Power[u] += 1
    Power[v] += 1
    Edges.append((u,v))

onecount = sum(value == 1 for value in Power.values())
if onecount == 2:
    for i in range(n-1):
        print(i)
else:
    left = 0
    right = n-2
    for (u,v) in Edges:
        if (Power[u] == 1) or (Power[v] == 1):
            print(left)
            left += 1
        else:
            print(right)
            right -= 1

