import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
String[] data = new String[n];
for (int i = 0; i < n; i++) {
data[i] = String.valueOf(sc.nextInt());
}
int m = sc.nextInt();
TreeSet<Integer> set = new TreeSet<>();
for (int i = 0; i < m; i++) {
set.add(sc.nextInt());
}
// 统计数据个数
int count = 0;
// 标识是否出现匹配的数据
boolean flag = false;
StringBuilder sb = new StringBuilder();
for (Integer digit : set) {
String regex = String.valueOf(digit);
List<String> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
String number = data[i];
if (number.contains(regex)) {
list.add(String.valueOf(i)); // 存储元素坐标
list.add(number); // 存储元素本身
}
}
int size = list.size();
if (size > 0) {
flag = true;
String listStr = String.join(" ", list.toArray(new String[size]));
sb.append(" ").append(regex)
.append(" ").append(size / 2) // 统计匹配元素的个数
.append(" ").append(listStr);
// 统计所有元素的个数
count += 2 + size;
}
}
if (flag) {
System.out.println(count + sb.toString());
}
}
}
}