// Arup Guha
// 4/6/2022
// Solution to 2022 USACO March Silver Problem: Subset Equality.

import java.util.*;

public class subseteq {

	public static void main(String[] args) {
	
		// Get strings.
		Scanner stdin = new Scanner(System.in);
		char[] s = stdin.next().toCharArray();
		char[] t = stdin.next().toCharArray();
		
		// Store locations of each letter in each string.
		ArrayList<Integer>[] locS = getLocs(s);
		ArrayList<Integer>[] locT = getLocs(t);
		
		// See which relative orderings of pairs of strings are preserved.
		boolean[][] okay = new boolean[18][18];
		for (int i=0; i<18; i++) {
			for (int j=i+1; j<18; j++) {
				ArrayList<Boolean> tmp1 = getOrder(locS[i], locS[j]);
				ArrayList<Boolean> tmp2 = getOrder(locT[i], locT[j]);
				okay[i][j] = equal(tmp1, tmp2);
			}
		}
		
		int numQ = stdin.nextInt();
		
		// Process queries.
		for (int i=0; i<numQ; i++) {
		
			// Get the query.
			char[] q = stdin.next().toCharArray();
			
			// Every pair within the subset must be consistent, so we want all yes's.
			boolean res = true;
			for (int j=0; j<q.length; j++) {
				for (int k=j+1; k<q.length; k++) {
					res = res && okay[q[j]-'a'][q[k]-'a'];
					if (!res) break;
				}
				if (!res) break;
			}
			
			// Special case for length 1.
			if (q.length == 1) {
				res = locS[q[0]-'a'].size() == locT[q[0]-'a'].size();
			}
		
			// What we print.
			if (res) System.out.print("Y");
			else System.out.print("N");
		}
		System.out.println();
	}
	
	// Returns an array of lists of where each letter is.
	public static ArrayList<Integer>[] getLocs(char[] s) {
		ArrayList<Integer>[] locs = new ArrayList[18];
		for (int i=0; i<18; i++) locs[i] = new ArrayList<Integer>();
		for (int i=0; i<s.length; i++)
			locs[s[i]-'a'].add(i);
		return locs;
	}
	
	// Returns relative ordering of c1 and c2 based on the location arrays.
	public static ArrayList<Boolean> getOrder(ArrayList<Integer> list1, ArrayList<Integer> list2) {
	
		int i = 0, j = 0;
		ArrayList<Boolean> res = new ArrayList<Boolean>();
		
		// Basically merging the lists, I put false if from list 1, true if from list 2.
		while (i<list1.size() || j<list2.size()) {
			
			// Next item comes from list 1.
			if (j == list2.size() || (i<list1.size() && list1.get(i) < list2.get(j))) {
				res.add(false);
				i++;
			}
			
			// List 2...
			else {
				res.add(true);
				j++;
			}
		}
		return res;
	}
	
	// Returns true iff list1 and list2 are equal lists.
	public static boolean equal(ArrayList<Boolean> list1, ArrayList<Boolean> list2) {
	
		// Can't be!
		if (list1.size() != list2.size()) return false;
		
		// Everything has to match.
		for (int i=0; i<list1.size(); i++)
			if (list1.get(i) != list2.get(i))
				return false;
		return true;
	}
}