from sys import stdin
from queue import deque
from collections import defaultdict
from copy import copy
#input = stdin.readline
def read_tuple(): return map(int,input().split())
def read_int(): return int(input())
def read_list(): return list(map(int,input().split()))
def read_str_list(): return list(input().split())

n = read_int()
tree = defaultdict(list)
queries = []
for _ in range(n-1):
    u,v = read_tuple()
    queries.append( (u,v) )
    tree[u].append(v)
    tree[v].append(u)

ans = defaultdict(int)
i = 0
while i!=n-1:
    ntree = copy(tree)
    keys = list(ntree.keys())
    for u in keys:
        if len(tree[u]) == 1:
            v = ntree.pop(u)[0]
            ans[ (u,v) ] = i
            ans[ (v,u) ] = i
            ntree[v].remove(u)
            i+=1
    tree = ntree
            
for u,v in queries:
    print( ans[ (u,v) ] )