import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class fraud_petr {
    public static void main(String[] args) {
        InputStream inputStream;
        try {
            inputStream = new FileInputStream("fraud.in");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        OutputStream outputStream;
        try {
            outputStream = new FileOutputStream("fraud.out");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Fraud solver = new Fraud();
        solver.solve(1, in, out);
        out.close();
    }
}
 
class Fraud {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        String s = in.next();
        int n = in.nextInt();
        String[] c = new String[n];
        for (int i = 0; i < n; ++i) c[i] = in.next();
        int cnt = 0;
        for (int i = 0; i < n; ++i) if (match(s, c[i])) ++cnt;
        out.println(cnt);
        for (int i = 0; i < n; ++i) if (match(s, c[i])) out.println(c[i]);
    }
 
    private boolean match(String a, String b) {
        for (int i = 0; i < a.length(); ++i)
            if (a.charAt(i) != b.charAt(i) && a.charAt(i) != '*') return false;
        return true;
    }
}
 
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
 
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
 
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    }