
import sys
input=sys.stdin.readline
from collections import defaultdict as dd,deque
n=int(input())
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)
        #lee[i]=1
cou=0
for i in le:
    a=i
    b=d[i][0]
    res[(a,b)]=cou
    res[(b,a)]=cou
    cou+=1
    if(cou==2):
        break
for i in inp:
    if(res[i]!=-1):
        print(res[i])
    else:
        print(cou)
        cou+=1