Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2015. október 21.

October 21, 2015 10:00 AM – October 21, 2015 3:00 PM

Bafana Bafana

Team practice is very important not only for programming contests but also for football. With team practice, players can learn cooperating with team mates. For playing as a team, improvement of passing skills is very important. Passing is a great way of getting the ball upfield and reduces the risk of giving the ball away.

Carlos Alberto Parreira, the coach of Bafana Bafana, also wants his players to practice passing a lot. That's why, while in the training camp for soccer world cup 2010, every day he asks all of the players who are present in practice to stand in a circle and practice passing. If N players are in practice, he gives each of the players a distinct number from 1 to N and asks them to stand sequentially, so that player 2 will stand on the right side of player 1, player 3 will stand on the right side of player 2, and so on. As they are in a circle, player 1 will stand right to player N.

The rule of passing practice is the following: Parreira will give the ball to player K, and practice will start. Practice will come to an end after P passes. In each pass, a player will give the ball to his partner who is on his immediate right side. After P passes, the player who owns the ball at that moment will give the ball back to Parreira.

Parreira wants to be ensured that his players practice according to the rule. So he wants a program that will tell him which player will give the ball back to him. So after taking the ball from this person, he can be happy that the players play according to the rules. Otherwise, he will ask them to start from the beginning.

Input Specification

The input starts with an integer T (T ≤ 1000), the number of test cases. Each test case will contain three integers in a single line, separated by spaces: N (2 ≤ N ≤ 23), K (1 ≤ K ≤ N), and P (1 ≤ P ≤ 200).

Output Specification

For each test case, output a single line giving the case number followed by the Bafana player number who will give the ball back to Parreira. See the sample output for the exact format.

Sample Input

  1. 3
  2. 5 2 5
  3. 6 3 5
  4. 4 1 3
download as text file

Output for Sample Input

  1. Case 1: 2
  2. Case 2: 2
  3. Case 3: 4
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019