// Arup Guha
// 3/12/2014
// Solution to 2014 FHSPS Playoff Problem: Dallas Buyers' Club(dallas)

import java.util.*;

public class dallas {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in names.
			int listSize = stdin.nextInt();
			String[] names = new String[listSize];
			for (int i=0; i<listSize; i++)
				names[i] = stdin.next();

			// List header
			System.out.println("List #"+loop+":");

			// Go through each subsequence.
			int evalSize = stdin.nextInt();
			for (int i=0; i<evalSize; i++) {

				// See if it's a match and output appropriately.
				String sub = stdin.next();
				if (match(names, sub))
					System.out.println(sub+": FOUND");
				else
					System.out.println(sub+": NOT FOUND");
			}
			System.out.println();
		}
	}

	// Returns true iff sub matches at least one string in list.
	public static boolean match(String[] list, String sub) {

		// Try each item individually and return true if we find a match.
		for (int i=0; i<list.length; i++)
			if (match(list[i], sub))
				return true;

		// If we get here, there is no match.
		return false;
	}

	// Returns true iff sub is a subsequence of str. We assume sub is non-empty here.
	public static boolean match(String str, String sub) {

		int j = 0;

		// Go through whole input string.
		for (int i=0; i < str.length(); i++) {

			// These letters match, greedily take it and move onto the next letter.
			if (str.charAt(i) == sub.charAt(j)) j++;

			// If we've matched every letter in our subsequence, we're good!
			if (j == sub.length()) return true;
		}

		// If we get here, everything didn't match.
		return false;
	}
}
