from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = lambda x: chr(96+x)

t = ii()
a = []
left = set()
right = set()
d = {}
for j in range(t-1):
    #n = ii()
    a.append(iia())
    left.add(a[j][0])
    right.add(a[j][1])
    d[a[j][1]] = j
#print(set(left))
#print(set(right))
leaf = list(set(right)-set(left))
ans = [-1]*(t-1)
#print(leaf)
ind = 1
x = []
for i in leaf:
    x.append(d[i])
x = x[::-1]
for i in x:
    ans[i] = ind
    ind+=1
    #print(ans)
for j in range(t-1):
    if(ans[j]==-1):
        ans[j] = ind%(t-1)
        ind+=1
if(t==3):
    for i in range(t-1):
        ans[i]%=2
if(t==2):
    print(0)
else:
    for i in ans:
        print(i)