import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right,bisect
n=int(input())
graph=defaultdict(lambda:[])
edges=[]
for i in range(n-1):
    a,b=map(int,stdin.readline().split())
    graph[a].append(b)
    graph[b].append(a)
    edges.append([a,b])
ma=0
mi=0
for i in graph.keys():
    if(len(graph[i])>ma):
        ma=len(graph[i])
        mi=i
if(ma>2):
    special=set()
    for i in graph[mi][:3]:
        special.add(tuple([mi,i]))
    scount=0
    rest=3 
    for i in edges:
        if tuple(i) in special or tuple(i[::-1]) in special:
            print(scount)
            scount+=1
        else:
            print(rest)
            rest+=1
else:
    for i in range(n-1):
        print(i)
