#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int main() {
int t;
cin >> t;
for (int z = 0; z < t; z++) {
string date;
cin >> date;
vector<int> days = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int month = (date[4]-'0') * 10 + (date[5]-'0');
if (month > 12 || month <= 0) { cout << "#" << (z + 1) << " " << "-1" << endl; continue; }
int day = (date[6]-'0') * 10 + (date[7]-'0');
if (day <= 0 || day > days[month - 1]) { cout << "#" << (z + 1) << " " << "-1" << endl; continue; }
cout << "#" << (z + 1) << " ";
for (int i = 0; i < 4; i++) {
cout << date[i];
}
cout << "/" << date[4] << date[5] << "/" << date[6] << date[7] << endl;
}
}