D

Drutojan Express

Input

Standard Input

Output

Standard Output

 

Well, 5 of the trouble makers are going to Dinajpur by the well known train Drutojan Express. The 5 trouble makers – Ja, Sam, Sha, Sid and Tan were discussing about how to create trouble in Dinajpur. But after a while they themselves got into trouble. Well, let me share the story with you.

The tickets they bought were the cause of the problem. See, 4 of those tickets all shared the same compartment while the other ticket was for a different compartment. As you can guess, no one was willing to go to the compartment where the single seat is.

After almost two hours of quarrel and unmentionable fights, they were exhausted; so they came up with a plan. The plan is: each of them will make a list containing names of the other persons. Now, if a person goes to the single seat, first he will stay there for M minutes. After that he will exchange his seat with the person who is on top of his own list. At this point he will also update his list by removing this name from top of his list and add the name at the bottom of the list.

This will go on all through their journey. So you are given their lists, the person who is on the single seat right now and the total time N (in minutes) for which they would be traveling. For each of them, you have to find the total time he will stay in the single seat. You can assume that its takes 2 minutes to exchange seats. And you will start time counting from the 0th minute. That means if M is 5 and the first person who is in the single is Sid, then he will exchange after 5 minutes. Then from the 7th minute the next person in his list (Sha) will be in that seat. Remember that a person can leave the seat without staying M minutes if the train reaches the destination within M.

Input

The first line of the input will contain an integer T ( 500) denoting the number of cases.

Each case starts with two integers M (2M30) and N(10N1000) and the name of the person who is in the single seat. Then there will be 5 lines. Each of the lines represents a list. A list contains and integer k (1k20) and k names separated by spaces. That means this list has k members and the names are listed from top to bottom. These 5 lines contain lists of Ja, Sam, Sha, Sid and Tan respectively. In a list, a name can occur more than once. You can assume no one will put his own name in his list.

Output

For each case print the the case number in a single line. Then print 5 lines for each person (in the order shown below) and total time he will be on the single seat. Check samples for details. Report the names as in input.

Sample Input

Sample Output

1

3 11 Ja

5 Tan Sid Sam Sha Tan

1 Ja

1 Ja

1 Ja

1 Ja

 

Case 1:

Ja 4

Sam 0

Sha 0

Sid 0

Tan 3

 

 

Explanation

First 3 minutes Ja was on the single seat

After that he exchanged his seat with Tan, it took 2 minutes

After that Tan was there for 3 minutes.

He exchanged with Ja again, and it took 2 minutes

Ja stayed for 1 minute and they reached the destination. So, Ja was there for 4 minutes and Tan was there for 3 minutes.