import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;

public class fraud_gk {
    static Scanner in;
    static PrintWriter out;

    void run() {
        Pattern pattern = Pattern.compile(in.next().replace("*", ".?"));

        int n = in.nextInt();
        StringBuilder sb = new StringBuilder();
        int k = 0;
        for (int i = 0; i < n; i++) {
            String number = in.next();
            if (pattern.matcher(number).matches()) {
                k++;
                sb.append(number).append("\n");
            }
        }

        out.println(k);
        out.print(sb);
    }

    public static void main(String[] args) throws Exception {
        in = new Scanner(new File("fraud.in"));
        out = new PrintWriter("fraud.out");

        new fraud_gk().run();

        in.close();
        out.close();
    }
}
