Zig and Zag play a word game. Zig says one lowercase letter, and Zag answers with a word that starts with that letter. The word must come from a fixed word list, and among the words on the list that start with that letter, Zag says the one he has said the fewest times so far. If several words tie, Zag says the one that comes first in alphabetical order. For every letter Zig says, a word is always available.
You are given a list of K distinct words and the N letters Zig says. Write a program that prints the N words Zag says, in order.