1.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 280 - Vertex
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=216
*
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version X.0, 07/06/2009
*
* Status : Accepted
* Runtime: 1.668
*/

import java.util.*;


public class Vertex2
{
public static void main(String... args)
{
int[][] area;
Scanner sc = new Scanner(System.in);
int vertices;
int starter;
int vertex;
int testCases;
int testNumber;

while((vertices = sc.nextInt()) != 0)
{
area = new int[vertices][vertices];

while((starter = sc.nextInt()) != 0)
{
while((vertex = sc.nextInt()) != 0)
{
area[starter-1][vertex-1] = 1;
}
}



for(int k = 0; k < vertices; k++)
for(int i = 0; i < vertices; i++)
if(area[i][k] == 1)
for(int j = 0; j < vertices; j++)
if(area[k][j] == 1)
area[i][j] = 1;

//System.out.println(Arrays.deepToString(area).replace("],", "\n"));
testCases = sc.nextInt();
for(int i = 0; i<testCases; i++)
{
testNumber = sc.nextInt();
int c = 0;
for(int k = 0; k < vertices; k++)
if(area[testNumber-1][k] == 0)
c++;

System.out.print(c);
for(int k = 0; k < vertices; k++)
if(area[testNumber-1][k] == 0)
System.out.print(" "+(k+1));

System.out.println();
}
}
}
}