// Arup Guha
// 2/23/2013
// Solution to 2013 Mercer Contest Problem #9: Proper Subsets
import java.util.*;

public class prob9 {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = Integer.parseInt(stdin.nextLine().trim());

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			StringTokenizer tok = new StringTokenizer(stdin.nextLine(), "{}, ");
			ArrayList<String> mainSet = new ArrayList<String>();

			// Add all items from list.
			while (tok.hasMoreTokens())
				mainSet.add(tok.nextToken().toLowerCase());

			tok = new StringTokenizer(stdin.nextLine(), "{}, ");
			ArrayList<String> subset = new ArrayList<String>();

			// Add all items from supposed proper subset.
			while (tok.hasMoreTokens())
				subset.add(tok.nextToken().toLowerCase());

			if (isProperSubset(subset, mainSet))
				System.out.println(loop+": YES");
			else
				System.out.println(loop+": NO");
		}
	}

	// Returns true iff every item in list1 exists in list2 and if list2 had at least one
	// extra unique item. Does brute force since the sets are small.
	public static boolean isProperSubset(ArrayList<String> list1, ArrayList<String> list2) {

		// We'll check off each item in list2 that appears in list 1.
		boolean[] items = new boolean[list2.size()];

		// Check each item
		for (int i=0; i<list1.size(); i++) {

			boolean found = false;
			for (int j=0; j<list2.size(); j++) {
				if (list1.get(i).equals(list2.get(j))) {
					items[j] = true;
					found = true;
				}
			}

			if (!found) return false;
		}

		// If there's an item not found, it's a proper subset.
		for (int i=0; i<items.length; i++)
			if (!items[i])
				return true;

		// All items is list1 are in list2.
		return false;
	}
}