Drutojan Express

Well, 5 of the trouble makers are going to Di- najpur by the well known train Drutojan Ex- press. The 5 trouble makers — Ja, Sam, Sha, Sid and Tan were discussing about how to cre- ate 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 compart- ment where the single seat is. After almost two hours of quarrel and un- mentionable 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 0-th 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 7-th 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. EachcasestartswithtwointegersM (2≤M ≤30)andN (10≤N ≤1000)andthenameof 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 (1 ≤ k ≤ 20) 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. Explanation: • First 3 minutes Ja was on the single seat

2/2 • 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. Sample Input 1 3 11 Ja 5 Tan Sid Sam Sha Tan 1 Ja 1 Ja 1 Ja 1 Ja Sample Output Case 1: Ja 4 Sam 0 Sha 0 Sid 0 Tan 3