let firStr;
while ((firStr = readline())) {
let secStr = readline();
let I = firStr.split(" ").splice(1);
let R = secStr.split(" ").splice(1);
let sortedR = Array.from(new Set(R.sort((a, b) => +a - +b)));
// [0, 3, 6]
let result = {};
sortedR.forEach((item) => {
let obj = {};
I.forEach((v, i) => {
if (v.includes(item)) {
obj[i] = v;
}
});
if (Object.keys(obj).length) {
result[item] = obj;
}
});
let str = "";
Object.keys(result).forEach((v) => {
str = `${str} ${v} ${Object.keys(result[v]).length}`
Object.keys(result[v]).forEach(el => {
str = `${str} ${el} ${result[v][el]}`
})
});
print(`${str.split(" ").length - 1}${str}`)
}