#include <iostream>
#include <sstream>
using namespace std;
int StringToInt(string text)
{
std::stringstream bufor(text);
int i;
bufor>>i;
return i;
}
string IntToString(int text)
{
std::stringstream bufor;
bufor<<text;
return bufor.str();
}
string ReverseString(string text)
{
string _text;
for(int i = text.length()-1;i >=0;i--)
_text += text[i];
return _text;
}
class time
{
private:
int hours;
int minutes;
string sTime;
string sHours;
string sMinutes;
public:
string GetStringHours()
{
return sHours;
}
string GetStringMinutes()
{
return sMinutes;
}
int GetHours()
{
return hours;
}
int GetMinutes()
{
return minutes;
}
void SetTime(std::string _time)
{
hours = StringToInt(_time.substr(0,2));
minutes = StringToInt(_time.substr(3,2));
SetTime();
}
string GetTime()
{
return sTime;
}
void AddMinutes(int _minut)
{
minutes += _minut;
SetTime();
}
void AddHours(int _hour)
{
hours += _hour;
SetTime();
}
private:
void CheckCompatibility()
{
int restOfMinutes = 0;
int restOfHours = 0;
if(minutes >= 60)
{
restOfMinutes = minutes % 60;
restOfHours = minutes / 60;
minutes = restOfMinutes;
hours += restOfHours;
CheckCompatibility();
}
if(hours > 23)
hours %= 24;
}
void SetTime()
{
CheckCompatibility();
sTime.clear();
sHours = IntToString(hours);
sMinutes = IntToString(minutes);
if(sHours.length() == 1) sHours = '0' + sHours;
if(sMinutes.length() == 1) sMinutes = '0' + sMinutes;
sTime = sHours;
sTime += ':';
sTime += sMinutes;
}
};
bool IsPalindrom(std::string palindrom)
{
for(std::size_t i = 0; i < palindrom.length() ; i++)
if( palindrom[i] != palindrom[palindrom.length()-1-i])
return false;
return true;
};
bool CheckIfIsPalindrom(time *_time)
{
string palindrom;
if(_time->GetHours() != 0)
{
palindrom += _time->GetStringHours();
palindrom += _time->GetStringMinutes();
return IsPalindrom(palindrom);
}
else
{
palindrom += _time->GetStringMinutes();
if(_time->GetMinutes() < 10)
return true;
else
return IsPalindrom(palindrom);
}
return false;
};
int main()
{
int n;
cin>>n;
string godzina;
time *czas = new time[n];
for( int i = 0; i < n ; i++ )
{
bool Palindrom = false;
cin>>godzina;
czas[i].SetTime(godzina);
czas[i].AddMinutes(1);
while(!CheckIfIsPalindrom(&czas[i]))
czas[i].AddMinutes(1);
cout<<czas[i].GetTime()<<endl;
};
delete []czas;
};