import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
 
/**
 * Created with IntelliJ IDEA.
 * User: poromov
 * Date: 27.11.13
 * Time: 13:56
 * To change this template use File | Settings | File Templates.
 */
public class fraud_bgp {
    public void solve() throws Exception {
        char[] p = nextToken().toCharArray();
        assert p.length == 9;
 
        List<String> ans = new ArrayList<String>();
 
        int n = nextInt();
        while (n --> 0) {
            char[] plate = nextToken().toCharArray();
            assert plate.length == 9;
 
            boolean good = true;
            for (int i = 0; i < plate.length; ++i) {
                if (plate[i] != p[i] && p[i] != '*') {
                    good = false;
                }
            }
 
            if (good) {
                ans.add(new String(plate));
            }
        }
 
        out.println(ans.size());
        for (String s : ans) {
            out.println(s);
        }
    }
 
 
    int nextInt() {
        return Integer.parseInt(nextToken());
    }
 
    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine()) ;
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken();
    }
 
    public static void main(String[] args) {
        new fraud_bgp().run();
    }
 
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;
    boolean eof;
 
    public void run() {
        try {
            br = new BufferedReader(new FileReader("fraud.in"));
            out = new PrintWriter("fraud.out");
            solve();
        } catch (Throwable t) {
            t.printStackTrace();
            System.exit(-1);
        } finally {
           out.close();
        }
    }
 
}