inp = open("birthday.in", "r")
outp = open("birthday.out", "w")

#months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
n = int(inp.readline())
dates = []

for s in inp:
    day, month = s.split()
    dates.append([int(day), int(month)])


def check(i):
    this_day = []
    
    for j in range(n):
        if (dates[i][0] == dates[j][0]):
            this_day.append(j)
    
    if (len(this_day) <= 1):
        return False

    flag = True
    for j in this_day:
        month = dates[j][1]
        num = 0
        for k in range(n):
            if (dates[k][1] == month):
                num += 1

        if (num <= 1):
            flag = False
            break

    return flag


precalc = [check(i) for i in range(n)]

for i in range(n):
    #print(i)
    if (not precalc[i]):
        continue

    num = 0
    for j in range(n):
        if (dates[j][1] == dates[i][1]):
            if (precalc[j]):
                num += 1

    if (num == 1):
        outp.write(str(dates[i][0]) + " " + str(dates[i][1]))
        exit(0)

print("No solution")