1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #11309 Counting Chaos
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1103
*
* @author Fabian Seidl
* @author Marcel Sachse
* @version 1.0, 29/04/2009
*
* Status : Accepted
* Runtime: 0.344
*/

import java.io.*;

public class Main
{

public static void main(String[] args) throws Exception
{

InputStreamReader bInput = new InputStreamReader(System.in);
BufferedReader bReader = new BufferedReader(bInput);

Writer out = new BufferedWriter(new PrintWriter(System.out));


for(int n = Integer.parseInt(bReader.readLine());n>0;n--)
{
String[] time = bReader.readLine().split(":");
int hh = Integer.parseInt(time[0]);
int mm = Integer.parseInt(time[1]);

while(true)
{
// um eine Minute weiterz¦hlen
mm++;

// †bertrag, wenn n¨tig
if(mm==60)
{
mm=0;
hh++;

if(hh==24)
{
hh=0;
}
}


// nur f¾hrende nullen von hh zu ignorieren
if(hh < 10)
{
// auch f¾hrende nullen von mm zu ignorieren
if(hh==0)
{
if(mm<10) break; // 00:0X
if(mm%10 == mm/10) break; // 00:XX
}
else if(hh == mm %10) break; // 0X:YX
}
// keine Nullen zu ignorieren
else if((hh%10)*10 + hh/10 == mm) break; // XY:YX

}

out.write(String.format("%02d:%02d\n", hh,mm));
}
out.flush();
}
}


2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #11309 Counting Chaos
*
* @author Julius Tschannerl
* @author David Leib
* @version 1.0, 06/23/2009
*
* Status : Accepted
* Runtime: 0.504
*/
import java.io.*;

public class Main {


public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int count = Integer.parseInt(br.readLine());

for(int i =0;i<count;i++){
String[] numbers = br.readLine().split(":");
int first = Integer.parseInt(numbers[0]);
int second = Integer.parseInt(numbers[1]);
int firstdigit = second % 10;
int seconddigit = second /10;
if(first == 0){
if(second <= 8){
second++;
System.out.println("00:0"+ second);
}
else if(second>=9 && second <= 54){
if (firstdigit >= seconddigit){
seconddigit += 1;
}
System.out.printf("00:%01d%01d%n",seconddigit,seconddigit);
}
else
System.out.println("01:01");
}
else if(first < 10){
if(firstdigit < first){
System.out.printf("0%01d:%01d%01d%n",first,seconddigit,first);
}
else if(firstdigit >= first && seconddigit == 5){
if(first == 9){
System.out.println("10:01");
}
else{
first += 1;
System.out.printf("0%01d:0%01d%n",first,first);
}
}
else if(firstdigit >= first){

System.out.printf("0%01d:%01d%01d%n",first,(seconddigit+1),first);
}

}
else if(first >= 10){
int reverse = (first / 10) + (first%10)*10;
if (second >= reverse && reverse < 60){
first++;
reverse += 10;
if(first == 24){
first = 0;
reverse = 0;
}
else if(reverse >= 60){
first = 20;
reverse = (first / 10) + (first%10)*10;
}
}
else if(reverse >= 60){
first = 20;
reverse = (first / 10) + (first%10)*10;
}
System.out.printf("%02d:%02d%n",first,reverse);
}
}
}

}