Character = ("a".."z").to_a + ["ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"]
count = Hash.new {|hash, key| hash[key] = Hash.new}
Character.each do |first|
  Character.each do |second|
    count[first][second] = 0
  end
end
gets.to_i.times do
  gets.chomp.split.each do |word|
    first = Character.index(word[0, 2]) ? word.slice!(0, 2) : word.slice!(0)
    while word.size != 0 do
      second = Character.index(word[0, 2]) ? word.slice!(0, 2) : word.slice!(0)
      count[first][second] += 1
      first = second
    end
  end
end
count.each do |first, hash|
  second = "a"
  max = 0
  hash.each do |key, value|
    next if (max >= value) && (max >= value)
    next if max >= value
    max = value
    second = key
  end
  print "#{first} #{second} #{max}\n"
end