import java.util.*; import java.util.stream.Collectors;

public class Main {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()){
        //获取序列I
        String orderI = sc.nextLine();
        //获取序列R
        String orderR = sc.nextLine();
        String[] strsI = removeFirstElement(orderI.split(" "));
        String[] strsR = removeFirstElement(orderR.split(" "));
        List<String> listI = new ArrayList<>(Arrays.asList(strsI));
        List<String> listR = new ArrayList<>(Arrays.asList(strsR));
        //再对序列R进行排序和去重处理
        listR = listR.stream().sorted(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.parseInt(o1) - Integer.parseInt(o2);
            }
        }).distinct().collect(Collectors.toList());
        Map<Map<Integer,String>,Integer> kindCountMap = new LinkedHashMap<>();
        List<String> numList = new ArrayList<>();
        for (String s : listR) {
            int count = 0;
            Map<Integer,String> map = new LinkedHashMap<>();
            for (int i = 0; i < listI.size(); i++) {
                if(listI.get(i).contains(s)){
                    count++;
                    map.put(i,listI.get(i)+" "+s);
                }
            }
            if(count != 0) {
                numList.add(s);
                kindCountMap.put(map, count);
            }
        }
        int keyValueCount = 0;
        Set<Map<Integer, String>> keySet = kindCountMap.keySet();
        for (Map<Integer, String> map : keySet) {
            keyValueCount = keyValueCount + kindCountMap.get(map) * 2;
        }
        int totalCount = keyValueCount + kindCountMap.size() + numList.size();
        System.out.print(totalCount+" ");
        List<Map<Integer,String>> mapList = new ArrayList<>(keySet);
        for (int i = 0; i < numList.size();i++){
            System.out.print(numList.get(i)+" "+kindCountMap.get(mapList.get(i))+" ");
            Set<Integer> set = mapList.get(i).keySet();
            for (Integer integer : set) {
                System.out.print(integer+" "+mapList.get(i).get(integer).split(" ")[0]+" ");
            }
        }
        System.out.println();
    }
}

private static String[] removeFirstElement(String[] strs){
    String[] newStrs = new String[strs.length-1];
    System.arraycopy(strs,1,newStrs,0,strs.length-1);
    return newStrs;
}

}