MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
let = '@abcdefghijklmnopqrstuvwxyz'
n=ii()
deg=[0]*(10**5+10)
l=[]
it1,it2=0,n-2
for _ in range(n-1):
    x,y=f()
    deg[x]+=1
    deg[y]+=1
    l.append([x,y])
for i in l:
    if deg[i[0]]==1 or deg[i[1]]==1:
        print(it1)
        it1+=1
    else:
        print(it2)
        it2-=1
