Once upon a time there lived a king who had N sons. In his kingdom there were also N beautiful girls, and the king knew, for each of his sons, which of those girls he liked. The sons were young and light-headed, so a single son could like several girls.
The king asked his wizard to pick, for each son, one girl that he likes so that the son could marry her — and the wizard did it. Each son was assigned a girl he likes, and of course each girl may marry only one son.
Looking at the list, the king said: “I like the list, but I am not fully satisfied. For each son I want to know every girl he could marry. Naturally, after he marries any one of them, it must still be possible to assign every other son a different girl he likes.”
Formally, for each son i you must report all girls g such that i likes g and there exists a perfect matching (each son paired with a distinct girl he likes) in which son i is matched to girl g. Solve this problem to save the wizard's head.
The first line contains N — the number of the king's sons (1≤N≤2000).
Each of the next N lines describes the girls one son likes: first Ki — the number of girls — followed by Ki distinct integers between 1 and N denoting those girls. The sum of all Ki does not exceed 200000.
The last line contains the wizard's original list: N distinct integers, where the i-th number is the girl that son i marries in that list. The list is guaranteed to be valid, i.e. every son likes the girl assigned to him.
Output N lines. For son i, first print Li — the number of distinct girls he likes and could marry so that every other son can still be matched to a girl he likes. Then, on the same line, print those girls' numbers in ascending order.
(The original statement allowed printing the girls in any order; to make the answer unique for automatic grading, print them in ascending order.)