#include<iostream>
#include<sstream>
usig namespace std;
int main()
{
    int N;
    cin >> N;
    cin.ignore();
    for (int i=0; i < N; ++i)
    {
        string line;
        getline(cin, line);
        stringstream ss(line);
        string type, name, field2;
        ss >> type >> name >> field2;
        if (type == "Student")
        {
            int grade;
            try
            {
                grade=stoi(field2;)
            }
            catch(...)
            {
                cout << "Invalid input" << endl;
                continue;
            }
            if (grade < 1 || grade > 12)
        {
            cout<<"Invaid input"<< endl;
            continue;
        }
            cout << "Student: "<<name << " , Grade: "<< grade << endl;
        }
        else if (type== "Teacher")
        {
            string subject = field2;
            cout << "Teacher: " << name << ",Subject: " << subject << endl;
        }
        else
        {
            cout << "Invalid input" << endl;
        }
    }
    return 0;
}