King
In a distant kingdom, there lived a king who had n sons. In this kingdom, there were also n beautiful maidens, and the king was aware of which maidens each of his sons liked. Since the sons were young and carefree, they could be fond of multiple maidens simultaneously.
One day, the king instructed his advisor to find a suitable maiden for each son to marry. The advisor completed this task by selecting a maiden that each son liked, ensuring that each maiden was chosen by only one son.
After reviewing the list of brides, the king remarked: "I am pleased with this list, but I wish to know the complete list of maidens each son can marry. Naturally, all sons should have the chance to marry the maidens they like."
This task proved too challenging for the advisor. Help him avoid execution by solving it.
Input
The first line of the input contains the number n — the number of sons (1 ≤ n ≤ 2000). The following n lines provide lists of maidens that each son likes. Each line begins with k_i — the number of maidens the i-th son likes, followed by k_i numbers indicating the indices of these maidens. The total of all k_i values does not exceed 200000.
The last line of the input contains the list compiled by the advisor — n distinct numbers from 1 to n, representing the index of the maiden each son can marry. It is guaranteed that the list is correct, meaning each son likes the maiden chosen for him.
Output
The output should consist of n lines. For each son, output l_i — the number of different maidens he can marry. Then, list l_i numbers — the indices of these maidens in any order.