#include <stdio.h>
#define N_VERTICES_NO_MIN 1
#define N_VERTICES_NO_MAX (100 + 10)
typedef enum
{
EDGE_NO_0,
EDGE_YES_1
}EdgeExists;
typedef enum
{
PROCESSED_NO_0,
PROCESSED_ING_1,
PROCESSED_YES_2
}_VertexProcessedState;
typedef struct
{
_VertexProcessedState IsProcessed;
}_VertexInfo;
EdgeExists Edges[N_VERTICES_NO_MAX][N_VERTICES_NO_MAX];
int AdjacencyList[N_VERTICES_NO_MAX][N_VERTICES_NO_MAX];
_VertexInfo VertexInfo[N_VERTICES_NO_MAX];
int N_Vertex_No = 0;
int Start_Vertex_Count = 0, Start_Vertices[N_VERTICES_NO_MAX];
int Processed_Vertices[N_VERTICES_NO_MAX];
void DFS(int startVertex)
{
int i = 0;
VertexInfo[startVertex].IsProcessed = PROCESSED_ING_1;
for (i = 0; i < AdjacencyList[startVertex][N_VERTICES_NO_MAX - 1]; i++)
{
if (VertexInfo[AdjacencyList[startVertex][i]].IsProcessed == PROCESSED_NO_0)
{
DFS(AdjacencyList[startVertex][i]);
}
}
VertexInfo[startVertex].IsProcessed = PROCESSED_YES_2;
Processed_Vertices[Processed_Vertices[N_VERTICES_NO_MAX - 1]++] = startVertex;
}
void resetVertexProcessedInfo()
{
int i = 0;
for (i = 1; i <= N_Vertex_No; i++)
{
VertexInfo[i].IsProcessed = PROCESSED_NO_0;
}
}
void resetEdgesAdjacencyList(int noOfVertex)
{
int i = 0, j = 0;
for (i = 0; i <= noOfVertex; i++)
{
AdjacencyList[i][N_VERTICES_NO_MAX - 1] = 0;
VertexInfo[i].IsProcessed = PROCESSED_NO_0;
for (j = 0; j <= noOfVertex; j++)
{
Edges[i][j] = EDGE_NO_0;
}
}
}
void initialize()
{
resetEdgesAdjacencyList(N_VERTICES_NO_MAX);
}
void resetTestCase(int noOfVertex)
{
resetEdgesAdjacencyList(noOfVertex);
}
void scanEdges()
{
int vertex_from = 0;
while (scanf("%d", &vertex_from
) == 1 && vertex_from
!= 0) {
int vertex_to = 0;
while (scanf("%d", &vertex_to
) == 1 && vertex_to
!= 0) {
Edges[vertex_from][vertex_to] = EDGE_YES_1;
AdjacencyList[vertex_from][AdjacencyList[vertex_from][N_VERTICES_NO_MAX - 1]++] = vertex_to;
}
}
}
void scanStartVertices()
{
int start_Vertex_Index = 0;
scanf("%d", &Start_Vertex_Count
);
for (start_Vertex_Index = 0; start_Vertex_Index < Start_Vertex_Count; start_Vertex_Index++)
{
scanf("%d", &Start_Vertices
[start_Vertex_Index
]); }
}
void scanInput()
{
scanEdges();
scanStartVertices();
}
void processStartVertex(int startVertex)
{
int i = 0;
for (i = 0; i < AdjacencyList[startVertex][N_VERTICES_NO_MAX - 1]; i++)
{
if (VertexInfo[AdjacencyList[startVertex][i]].IsProcessed == PROCESSED_NO_0)
{
DFS(AdjacencyList[startVertex][i]);
}
}
}
void printResult()
{
int i = 0;
printf("%d", N_Vertex_No
- Processed_Vertices
[N_VERTICES_NO_MAX
- 1]); for (i = 1; i <= N_Vertex_No; i++)
{
if (VertexInfo[i].IsProcessed != PROCESSED_YES_2)
{
}
}
}
int main()
{
#ifdef __FREOPEN__
freopen("280 - Vertex.in", "r", stdin
); #endif
initialize();
while (scanf("%d", &N_Vertex_No
) == 1 && N_Vertex_No
!= 0) {
int startVertexIndex = 0;
scanInput();
for (startVertexIndex = 0; startVertexIndex < Start_Vertex_Count; startVertexIndex++)
{
Processed_Vertices[N_VERTICES_NO_MAX - 1] = 0;
processStartVertex(Start_Vertices[startVertexIndex]);
printResult();
resetVertexProcessedInfo();
}
resetTestCase(N_Vertex_No);
}
return 0;
}