The Social Network

Time Limit: 3000/2000 MS (Java/Others)

Memory Limit: 65768/65768 K (Java/Others)

Description

The social network system (SNS) helps people to keep connecting with their friends. Every user in SNS has a friends list. The user can read news posted by the users in his friends list. Friend relation is symmetric - if A is a friend of B, B is always a friend of A.

Another important function in SNS is friend recommendation. One effective way to recommend friends is recommend by mutual friends. A mutual friend between two users A and B, is a user who is a friend of both A and B. A user can not be a friend of himself. For a specific user A, the system will recommend the user who is not himself or his friend, and has mutual friends with A. If more than one such user exists, recommend the one has most mutual friends with A. If still a tie exists, output all of them.

Input

The first line is a integer T (T≤100), the number of test case.
The beginning of each test case is two integers N and Q, the number of friend relationship and the number of query. 1 ≤ N, Q ≤ 1000
The following N lines each contain two different names separated by a single space. Each name consisted by only lowercase letters, and its length is less than or equal to 15. This means the two users are friends. No friend relationship will be given more than once.
The following Q lines each describe a query. Each line contain one user name. The data guarantee that this name appears at least once in above N lines.

Output

For each case, you should output one line containing “Case k: ” first, where k indicates the case number and counts from one. Then for each query, output one line, contains one or more names of recommended friends, separate by a single space, sorted by alphabetical order. If no persons can be recommended, output one line contains “-”.

Sample Input

1 10 11 hongshu digua yingying hongshu xmm hongshu huaxianzi xmm tangjiejie huaxianzi xhmz yingying digua xhmz zt tangjiejie xmm lcy notonlysuccess ljq hongshu digua yingying xmm huaxianzi tangjiejie xhmz zt lcy notonlysuccess ljq

Sample Output

Case 1: xhmz yingying digua digua tangjiejie yingying hongshu lcy zt xmm hongshu huaxianzi hongshu huaxianzi - -

Hint

lcy

Source

The 36th ACM/ICPC Asia Regional Chengdu Sit

提交代码