// Arup Guha
// 2/10/2016
// Alternate Solution to 2008 UCF HS Question: FaceSpace Friends

import java.util.*;

public class friends2 {

	// Important items for each case.
	public static int n;
	public static String[] names;
	public static HashMap<String,Integer> map;
	public static ArrayList[] graph;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in the names.
			n = stdin.nextInt();
			names = new String[n];
			map = new HashMap<String,Integer>();
			for (int i=0; i<n; i++) {
				names[i] = stdin.next();
				map.put(names[i], i);
			}

			// Set up the graph.
			graph = new ArrayList[n];
			for (int i=0; i<n; i++)
				graph[i] = new ArrayList<Integer>();

			// Add edges.
			int e = stdin.nextInt();
			for (int i=0; i<e; i++) {
				int v1 = map.get(stdin.next());
				int v2 = map.get(stdin.next());
				graph[v1].add(v2);
				graph[v2].add(v1);
			}

			// Case header.
			System.out.println("Social Network "+loop+":");

			// Just get your score...
			int myscore = score(map.get("You"));

			// Process each query for this case.
			int numComp = stdin.nextInt();
			for (int i=0; i<numComp; i++) {

				String name = stdin.next();
				int theirscore = 0;

				// Score them only if they are in the network.
				if (map.containsKey(name)) theirscore = score(map.get(name));

				// Output result.
				System.out.println("   "+name+": Difference of "+(myscore-theirscore)+" point(s).");
			}

			// Blank line after a case.
			System.out.println();
		}
	}

	public static int score(int v) {

		// Direct friends are easy.
		int direct = graph[v].size();

		// Run DFS.
		boolean[] visited = new boolean[n];
		dfs(v, visited);

		// Add extended # of friends.
		int sum = 0;
		for (int i=0; i<n; i++)
			if (i != v && visited[i])
				sum++;

		// Ta da!
		return sum+direct;
	}

	public static void dfs(int v, boolean[] visited) {

		// Mark it.
		visited[v] = true;

		// Recursively DFS on all unvisited neighbors.
		for (int i=0; i<graph[v].size(); i++) {
			int next = ((ArrayList<Integer>)graph[v]).get(i);
			if (!visited[next])
				dfs(next, visited);
		}
	}
}