1. 

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS2010
* Problem: 11805 A Contest from BUBT, Bangladesh, B Bafana Bafana
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=13&page=show_contest&contest=253
*
* @author Barny Porcio
* @version 1.0, 06/27/2010
*
* Status : Accepted
* Runtime: 0.2
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class ContestB {

/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
StringTokenizer st;
for (int c = 1; c <= cases; ++c){
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int P = Integer.parseInt(st.nextToken());
int res = (K+P)%N;
if (res == 0)
res = N;
System.out.println("Case "+c+": "+ res);


}
}

}

2.

/**
* ACM Programming
* Problem: 11805 - Bafana Bafana
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=226&problem=2905&mosmsg=Submission+received+with+ID+8066512
* Time: 0.192
* ACCEPTED
* @author Christoph Miesel
*/

import java.io.*;
import java.util.*;

public class BafanaBafana
{
static int N,K,P,player,diff;
public static void main(String[] args) throws IOException
{
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer t = new StringTokenizer(r.readLine());
int cases = Integer.parseInt(t.nextToken());
for(int c = 1; c <= cases; ++c)
{
t = new StringTokenizer(r.readLine());
N = Integer.parseInt(t.nextToken());
K = Integer.parseInt(t.nextToken());
P = Integer.parseInt(t.nextToken());
player = K;
while(P != 0)
{
diff = N-player;
if(P <= diff)
{

player += P;
P = 0;
//System.out.println("if "+player);
}
else
{

P -= (diff+1);
player = 1;
//System.out.println("else "+player);
}
}
System.out.println("Case "+c+": "+player);
}
}

}