import java.util.*;

/**
 * HJ25 数据分类处理
 */
public class HJ025 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int m = sc.nextInt();
            String[] arrI = new String[m];
            for (int i = 0; i < m; i++) {
                arrI[i] = sc.next();
            }
            int n = sc.nextInt();
            int[] arrR = new int[n];
            for (int i = 0; i < n; i++) {
                arrR[i] = sc.nextInt();
            }
            System.out.println(suoyin(arrI, arrR));
        }
        sc.close();
    }

    private static String suoyin(String[] arrI, int[] arrR) {
        Arrays.sort(arrR); // 将序列R排序
        String res = "";
        int sum = 0;
        for (int i = 0; i < arrR.length; i++) {
            if (i == 0 || arrR[i] != arrR[i - 1]) {
                int count = 0;
                String s = "";
                String str = String.valueOf(arrR[i]);
                for (int j = 0; j < arrI.length; j++) {
                    if (arrI[j].contains(str)) {
                        count++;
                        s = s + j + " " + arrI[j] + " ";
                    }
                }
                if (count > 0) {
                    sum = sum + count;
                    res = res + arrR[i] + " " + count + " " + s;
                }
            }

        }
        String[] str = res.split(" ");
        res = str.length + " " + res;
        return res;
    }
}