
import std.stdio;
import std.string;
import std.algorithm;
import std.range;
import std.array;
import std.conv;

string[] search_words(string[] lines, char prefix) {
  string[] res;
  foreach(line; lines) {
    auto words = line.split(" ");
    foreach(word; words) {
      if (word[0] == prefix) res ~= word;
    }
  }
  return res.sort.uniq.array;
}

void main() {
  while(true) {
    int times = readln.chomp.to!(int);
    if (times == 0) break;
    string[] lines;
    foreach(t; 0..times) lines ~= readln.chomp;
    char prefix = readln.chomp[0];
    auto res = search_words(lines, prefix);
    writeln((res == []) ? "NA" : res.join(" "));
  }
}