import sys


n = int(input())
a = []
b = dict()
num = False
a = list(map(str.strip, sys.stdin))
for i in range(n - 1):
    if a[i][0] in b:
        b[a[i][0]] += 1
    else:
        b[a[i][0]] = 1
    if a[i][1] in b:
        b[a[i][1]] += 1
    else:
        b[a[i][1]] = 1
    if b[a[i][1]] == 3:
        num = a[i][1]
        break
    if b[a[i][0]] == 3:
        num = a[i][0]
        break
count = 0
count2 = 3
if not num:
    for i in range(n - 1):
        print(count)
        count += 1
else:
    for i in range(n - 1):
        if (num in a[i]) and (count < 3):
            print(count)
            count += 1
        else:
            print(count2)
            count2 += 1

