n = int(input())
graph = {}
values = {}
order = []
for i in range(n):
    graph[i+1] = []
    values[i] = -1
val = -1
for i in range(n-1):
    a = input().split(' ')
    a[0] = int(a[0])
    a[1] = int(a[1])
    order.append(a)
    graph[a[0]].append(a[1])
    graph[a[1]].append(a[0])
    if len(graph[a[0]]) >= 3:
        val = a[0]
    if len(graph[a[1]]) >= 3:
        val = a[1]
if val == -1:
    for i in range(n-1):
        print(i)
else:
    count = 0
    for i in range(n-1):
        if order[i][0] == val or order[i][1] == val:
            values[i] = count
            count = count + 1
    for i in range(n):
        if values[i] == -1:
            values[i] = count
            count = count + 1
    for i in range(n-1):
        print(values[i])
