// Travis Roe
// 7/23/08
// Solution to BHCSI Contest Problem: Traffic
import java.util.*;

public class traffic{

    public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int numCases = scanner.nextInt();

		// Go through all of the cases.
		for(int curCase = 0; curCase < numCases; curCase++){

	    	int numEdges = scanner.nextInt();
	    	int[][] matrix = new int[numEdges][numEdges];

	    	// Store the adjacency matrix for this graph.
	    	for(int x = 0; x < numEdges; x++){

				int edgesPer = scanner.nextInt();
				for(int y = 0; y < edgesPer; y++){
		    		int toEdge = scanner.nextInt() - 1;
		    		matrix[x][toEdge] = 1;
				}
	    	}

	    	int numAccidents = scanner.nextInt();

	    	System.out.printf("City #%d%n", (curCase+1));

			// Go through each accident.
	    	for(int x = 0; x < numAccidents; x++){

				int accident = scanner.nextInt() - 1;
				System.out.println(testCase(matrix, accident)? "no":"yes");
	    	}

	    	System.out.println();
		}
    }

    //returns true if all the places cane be visited, false otherwise
    public static boolean testCase(int[][] matrix, int closed){

		boolean visited[] = new boolean[matrix.length];

		// Here's the trick - mark this one spot as visited, then see
		// if you can reach all the rest from one of the other nodes.
		// By marking it visited, the dfs never tries to branch off this
		// one node.
		visited[closed] = true;

		// Travis loves the ternary operator! Basically, the key is that you
		// have to start the dfs at a node different than the accident node,
		// so he starts at node 0 unless it's the accident node, otherwise,
		// he starts at node 1.
		dfs(matrix,closed == 0? 1:0, visited);
		for(boolean b : visited){
	    	if(!b) return false;
		}
		return true;
    }

	// Marks all the places you can reach from index in the graph stored in
	// matrix. visited keeps track of our progress.
    public static void dfs(int[][] matrix, int index, boolean[] visited){

		// Once we've visited something, we can't go from here again, or
		// we'll have infinite recursion!
		if(visited[index]) return;

		// Okay, now mark this node as visited.
		visited[index] = true;

		// Here we visit all of its neighbors.
		for(int x = 0; x < matrix.length; x++){
	    	if(matrix[x][index] == 1)
				dfs(matrix, x, visited);
		}
    }
}
