1. 

/*
* ACM Contest training
* Problem: 11309 - Counting Chaos
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=25&problem=2284
*
* @author Christoph Goettschkes
* @version 1.0, 01/06/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.012
*/

#include <stdio.h>

int hh[2];
int mm[2];

void nextTime() {
mm[1]++;
if (mm[1] < 10) {
return;
}

mm[1] = 0, mm[0]++;

if (mm[0] < 6) {
return;
}

mm[0] = 0, hh[1]++;

if ((hh[0] < 2 && hh[1] < 10) || hh[1] < 4) {
return;
}

hh[1] = 0, hh[0]++;

if (hh[0] <= 2) {
return;
}

hh[0] = 0;
}

int isPal() {
if (hh[0] == 0) {
if (hh[1] == 0) {
if (mm[0] == 0) {
return 1;
}
return mm[0] == mm[1];
}
return hh[1] == mm[1];
}
return hh[0] == mm[1] && hh[1] == mm[0];
}

int main() {
int tc, h, m;
scanf("%d", &tc);

while (tc-- > 0) {
scanf("%d:%d", &h, &m);
hh[0] = h / 10;
hh[1] = h % 10;
mm[0] = m / 10;
mm[1] = m % 10;

nextTime();

while (!isPal())
nextTime();

printf("%d%d:%d%d\n", hh[0], hh[1], mm[0], mm[1]);

}

return 0;
}