#! / usr / bin / env python3
#encoding: windows-1252

# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

import sys

if __name__ == "__main__":
    dezenas = []
    for i in range(60):
        dezenas.append([0] * 2)
        
    while True:
        linha = input()
    
        if linha in '0':
            break
    
        temp = linha.split(" ")

        for x in range(2, 8): 
            dezenas[int(temp[x]) - 1][0] = int(temp[x])
            dezenas[int(temp[x]) - 1][1] += 1
            print(temp[x])
                        
    dez = [[0,0],[0,0]]

    for x in range(len(dezenas)):
        trocou = False;
        for y in range(len(dezenas) - 1): 
            if dezenas[y][1] < dezenas[y + 1][1]: 
                trocou = True
                dez[0][0] = dezenas[y + 1][0]
                dez[0][1] = dezenas[y + 1][1]
                dezenas[y + 1][0] = dezenas[y][0]
                dezenas[y + 1][1] = dezenas[y][1]
                dezenas[y][0] = dez[0][0]
                dezenas[y][1] = dez[0][1]
        if not trocou:
            break

    for x in range(len(dezenas)):
        print(str(x+1) + " " + str(dezenas[x][0]) + " " + str(dezenas[x][1]))
    
    print("")
            
    sys.exit()

