// Arup Guha
// 2/1/2020
// Solution to UCF 2008 HS Contest Problem: Friends
// Written in Junior Knights to teach DFS.

import java.util.*;

public class friends {

	public static ArrayList[] g;
	public static int n;
	public static HashMap<String,Integer> map;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		for (int loop=1; loop<=nC; loop++) {
		
			// Number of people.
			n = stdin.nextInt();
			g = new ArrayList[n];
			for (int i=0; i<n; i++)
				g[i] = new ArrayList<Integer>();
			
			// Map people.
			map = new HashMap<String,Integer>();
			for (int i=0; i<n; i++)
				map.put(stdin.next(), i);
			
			// Add connections.
			int e = stdin.nextInt();
			for (int i=0; i<e; i++) {
				int v1 = map.get(stdin.next());
				int v2 = map.get(stdin.next());
				g[v1].add(v2);
				g[v2].add(v1);
			}
			
			// Get my score.
			int myscore = score("You");
			
			// Case header.
			System.out.println("Social Network "+loop+":");
			
			// Process queries.
			int numQ = stdin.nextInt();
			for (int i=0; i<numQ; i++) {
				String name = stdin.next();
				int otherscore = score(name);
				System.out.println("   "+name+": Difference of "+(myscore-otherscore)+" point(s).");
			}
			System.out.println();
		}
	}
	
	public static int score(String name) {
	
		// Important case - you are NOT on facespace...
		if (!map.containsKey(name)) return 0;
		
		// who i am
		int id = map.get(name);
		
		// You are in the network, add your neighbors, plus your component size, minus 1 (for you).
		return g[id].size() + dfsSize(id, new boolean[n])-1;
	}
	
	public static int dfsSize(int v, boolean[] used) {
	
		// Mark v.
		int res = 1;
		used[v] = true;
		
		// Go to all neighbors - add sizes of each of those subcomponents.
		for (Integer next: (ArrayList<Integer>)g[v])
			if (!used[next])
				res += dfsSize(next, used);
				
		// Here is my dfs size.
		return res;
	}
}