import java.util.Scanner;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
String[] strI = in.nextLine().split(" ");
int count = in.nextInt();
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < count; i++) {
map.put(in.nextInt(), 0);
}
int[] rArray = new int[map.size()];
int k = 0;
for (int temp : map.keySet()) {
rArray[k] = temp;
k = k + 1;
}
Arrays.sort(rArray);
String[] RArray = new String[map.size()];
for (int i = 0; i < map.size(); i++) {
RArray[i] = rArray[i] + "";
}
System.out.println(findDate(strI, RArray));
}
}
public static String findDate(String[] strI, String[] rArray) {
List<List<Integer>> list = new ArrayList<>();
for (int j = 0; j < rArray.length; j++) {
List<Integer> tempList = new ArrayList<>();
tempList.add(j);
for (int i = 1; i < strI.length; i++) {
if (strI[i].contains(rArray[j])) {
tempList.add(i - 1);
}
}
list.add(tempList);
}
StringBuffer sb1 = new StringBuffer();
int count = 0;
for (List tempList : list) {
if (tempList.size() >= 2) {
String Ri = rArray[(int)tempList.get(0)];
int count1 = tempList.size() - 1;
sb1.append(" ").append(Ri).append(" ").append(count1);
for (int i = 1; i < tempList.size(); i++) {
sb1.append(" ").append((int)tempList.get(i)).append(" ").append(strI[(int)tempList.get(i) + 1]);
}
count = count + count1 * 2 + 2;
}
}
StringBuffer sb = new StringBuffer();
sb.append(count).append(sb1);
return sb.toString();
}
}