import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Trie trie = new Trie();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0 ; i< n ;i++) {
String s = sc.next();
// String str = s.toLowerCase();
// trie.addWord(str);
trie.addWord(s);
}
int q = sc.nextInt();
for(int i = 0 ; i< q ; i++) {
String s = sc.next();
// String str = s.toLowerCase();
// trie.prefix(str);
trie.prefix(s);
}
}
}
class Trie {
private class Node{
char data;
HashMap<Character , Node> children;
boolean isTerminal;
Node(char data, boolean isTerminal){
this.data = data;
children = new HashMap<>();
this.isTerminal = isTerminal;
}
}
private Node root;
private int numWords;
private ArrayList<String> arr;
Trie(){
root = new Node('\0' , false);
numWords = 0;
}
public int numWords() {
return numWords;
}
public void addWord(String word) {
addWord(root , word);
}
private void addWord(Node parent , String word) {
if(word.length() == 0) {
if(parent.isTerminal) {
//word already exits
}else {
parent.isTerminal = true;
numWords++;
}
return;
}
char c = word.charAt(0);
String ros = word.substring(1);
Node child = parent.children.get(c);
if(child == null) {
child = new Node(c , false);
parent.children.put(c, child);
}
addWord(child , ros);
}
public void prefix(String word) {
prefix(root , word , "");
}
private void prefix(Node parent , String word , String osf) {
if(word.length() == 0) {
arr = new ArrayList<>();
display(parent , osf);
Collections.sort(arr);
for(String st: arr) {
System.out.println(st);
}
return;
}
char c = word.charAt(0);
String ros = word.substring(1);
Node child = parent.children.get(c);
if(child == null) {
System.out.println("No suggestions");
return;
}
prefix(child, ros, osf + c);
}
//osf : output so far
private void display(Node node , String osf) {
if(node.isTerminal) {
arr.add(osf);
//System.out.println(osf);
}
Set<Map.Entry<Character , Node>> entries = node.children.entrySet();
for(Map.Entry<Character , Node> entry : entries) {
display(entry.getValue() , osf + entry.getKey());
}
}
}