#include<iostream>
using namespace std;
int main(int argc, char** argv)
{
int test_case;
int T;
cin>>T;
int dayOfmonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
for(test_case = 1; test_case <= T; ++test_case)
{
int y, m, d;
string ymd;
cin >> ymd;
int y = atoi(ymd.substr(0, 4).c_str()); // c_str: string을 char로 변환
int m = atoi(ymd.substr(4, 2).c_str());
int d = atoi(ymd.substr(6, 2).c_str());
if(m>=1 && m<=12 && d<=31 && d<=dayOfmonth[m])
{
cout << "#" << test_case << " " << ymd.substr(0, 4) << "/" << ymd.substr(4, 2) << "/" << ymd.substr(6, 2) << endl;
} else
{
cout << "#" << test_case << " " << "-1" << endl;
}
}
return 0;
}