// Arup Guha
// 8/2/2026
// Solution to 1990 UCF HS Programming Contest Problem: On the Wild Side

import java.util.*;

public class wildcard {
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);	
		while (stdin.hasNext()) {
		
			// Get the pattern to match.
			String pattern = stdin.next();
			
			// Get the number of cases.
			int nC = stdin.nextInt();
			for (int i=0; i<nC; i++) {
			
				// Get text and match.
				String text = stdin.next();
				boolean match = matches(pattern, text);
				
				// Ta da!
				if (match)
					System.out.println(pattern+" matches "+text);
				else
					System.out.println(pattern+" does not match "+text);
			}
			
			// After each set.
			System.out.println();
		}
	}
	
	public static boolean matches(String pattern, String text) {
	
		// Finds where * is.
		int idx = pattern.indexOf("*");
	
		// I think these should work even to return "" as necessary.
		String left = pattern.substring(0, idx);
		String right = pattern.substring(idx+1);
		
		// Then this is what we want.
		return text.startsWith(left) && text.endsWith(right);
	}
}