#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4 * 7;
const int MINT = 15 * 60;
const int MAXT = 60 * 60;
int C[] = {6,2,5,5,4,5,6,3,7,6};
int B[1 + MAXN], W[1 + MAXN];
string get_time(int t)
{
int m = t / 60;
int s = t % 60;
stringstream ss;
ss << setfill('0') << setw(2) << m << ":" << setw(2) << s;
return ss.str();
}
int main()
{
for (int t = MINT; t < MAXT; ++t) {
int m = t / 60;
int s = t % 60;
int n = C[m / 10] + C[m % 10] + C[s / 10] + C[s % 10];
if (B[n] == 0) {
B[n] = t;
}
W[n] = t;
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << get_time(B[n]) << " " << get_time(W[n]) << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDQgKiA3Owpjb25zdCBpbnQgTUlOVCA9IDE1ICogNjA7CmNvbnN0IGludCBNQVhUID0gNjAgKiA2MDsKCmludCBDW10gPSB7NiwyLDUsNSw0LDUsNiwzLDcsNn07CmludCBCWzEgKyBNQVhOXSwgV1sxICsgTUFYTl07CgpzdHJpbmcgZ2V0X3RpbWUoaW50IHQpCnsKICAgIGludCBtID0gdCAvIDYwOwogICAgaW50IHMgPSB0ICUgNjA7CiAgICBzdHJpbmdzdHJlYW0gc3M7CiAgICBzcyA8PCBzZXRmaWxsKCcwJykgPDwgc2V0dygyKSA8PCBtIDw8ICI6IiA8PCBzZXR3KDIpIDw8IHM7CiAgICByZXR1cm4gc3Muc3RyKCk7Cn0KCmludCBtYWluKCkKewogICAgZm9yIChpbnQgdCA9IE1JTlQ7IHQgPCBNQVhUOyArK3QpIHsKICAgICAgICBpbnQgbSA9IHQgLyA2MDsKICAgICAgICBpbnQgcyA9IHQgJSA2MDsKICAgICAgICBpbnQgbiA9IENbbSAvIDEwXSArIENbbSAlIDEwXSArIENbcyAvIDEwXSArIENbcyAlIDEwXTsKICAgICAgICBpZiAoQltuXSA9PSAwKSB7CiAgICAgICAgICAgIEJbbl0gPSB0OwogICAgICAgIH0KICAgICAgICBXW25dID0gdDsKICAgIH0KICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luID4+IG47CiAgICAgICAgY291dCA8PCBnZXRfdGltZShCW25dKSA8PCAiICIgPDwgZ2V0X3RpbWUoV1tuXSkgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9