def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())

def L(): return list(R())

from collections import Counter 

import math
import sys

from itertools import permutations

import bisect

n=I()
e=[]
deg=[0]*n

for i in range(n-1):
    a,b=R()
    e.append([a-1,b-1])
    deg[a-1]+=1
    deg[b-1]+=1

x=max(deg)

if x==2:
    for i in range(n-1):
        print(i)

    exit()

ind=deg.index(x)

cnt=-1
ans=[0]*(n-1)
cnt2=0

for ed in e:
    a,b=ed
    cnt+=1

    if a==ind or b==ind:
        ans[cnt]=cnt2
        cnt2+=1

cnt=-1

for ed in e:
    a,b=ed
    cnt+=1

    if a!=ind and b!=ind:
        ans[cnt]=cnt2
        cnt2+=1

print(*ans,sep='\n')