
import sys
input=sys.stdin.readline
from collections import defaultdict as dd
n=int(input())
if(n==2):
    print(0)
else:
    d=dd(list)
    res=dd(lambda:-1)
    inp=[]
    for i in range(n-1):
        u,v=map(int,input().split())
        d[u].append(v)
        d[v].append(u)
        inp.append((u,v))
    #lee=[0]*(n+1)
    le=[]
    for i in range(1,n+1):
        if(len(d[i])==1):
            le.append(i)
    cou=0
    for i in le:
        a=i
        b=d[i][0]
        res[(a,b)]=cou
        res[(b,a)]=cou
        cou+=1
    #print(res)
    for i in inp:
        if(res[i]!=-1):
            print(res[i])
        else:
            print(cou)
            cou+=1