import atexit
import io
import sys
import math
from collections import defaultdict

_INPUT_LINES = sys.stdin.read().splitlines()
raw_input = iter(_INPUT_LINES).next
_OUTPUT_BUFFER = io.BytesIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def add(u,v):
   l[u].append(v) 
   l[v].append(u)
   
t=int(raw_input())
l=defaultdict(list)
d={}
for i in range(t-1):
    u,v=map(int,raw_input().split())
    d[u]=i
    d[v]=i
    add(u,v)
l1=[-1]*(t-1)
k=0
for i in l:
    if len(l[i])==1:
        l1[d[i]]=k
        k+=1
for i in l1:
    if i!=-1:
        print i
    else:
        print k
        k+=1