from collections import defaultdict, deque
from sys import stdin,stdout
n,A=int(input()),[]
for _i in range(n-1):
    A.append(tuple(int(x) for x in stdin.readline().strip().split(" ")))
    
hmap=defaultdict(list)
for a,b in A:
    hmap[a].append(b)
    hmap[b].append(a)

res=dict()
label=0
for i in range(1,n+1):
    if len(hmap[i])>=3:
        for x in hmap[i]:
            res[i,x]=label
            res[x,i]=label
            label+=1
        break
for x in A:
    if x not in res.keys():
        stdout.write(str(label)+"\n")
        label+=1
    else:
        stdout.write(str(res[x])+"\n")
