# maa chudaaye duniya
n = int(input())
graph = [[] for i in range(n+1)]
taken = [False for i in range(n-1)]
seen = [False for i in range(n+1)]
xx = []
mp_unit = {}
for i in range(n-1):
    xg = input()
    xx.append(xg)
    a, b = map(int, xg.split())
    graph[a].append(b)
    mp_unit[xg] = -1
# print(graph)
# print(mp_unit)
max_depth = 0
def dfs(parent, node):
    for i in graph[node]:
        dfs(node, i)
    # print('parent {} and node {}'.format(parent, node))
    if graph[node] == []:
        for ele in range(n-1):
            if not taken[ele]:
                taken[ele] = True
                mp_unit[str(parent) + ' ' + str(node)] = ele
                break
        # print('leaf')
def dfs2(parent, node):
    if parent:
        branch = str(parent) + ' ' + str(node)
        # print ('in dfs2 is {} - {}'.format(branch, mp_unit[branch]))
        if mp_unit[branch] == -1:
            for ele in range(n-1):
                if not taken[ele]:
                    taken[ele] = True
                    mp_unit[branch] = ele
                    break
    for i in graph[node]:
        dfs2(node, i)

dfs(None, 1)
dfs2(None, 1)
# print(mp_unit)
for i in xx:
    print(mp_unit[i])