#include<iostream>
#include<sstream>
#include<vector>
using namespace std;

struct student {
    string name;
    int grade;
};

struct Teacher {
    string name;
    string subject;
};

int main(){
    int N;
    string line;
    vector <Student> student ;
    vector <Teacher> teachers ;
    bool valid = true;
    
    cin>>N;
    cin.ignore();
    
    for(int i=0;i<N;++i){
        getline(cin,line);
        stringstream ss(line);
        string role;
        ss>>role;
        
        if(role=="Student"){
            string name;
            ss >> name >> grade;
            if(ss.fail()|| grade<1 || grade >12)
            {
                valid = false;
                break;
            }
            students.push_back({name,subject});
        }else if (role == "Teacher"){
            string name, subject;
            ss >> name >> subject;
            if(ss.fail()){
                valid=false;
                break;
            }
        }
        if(!valid){
            cout<<"invalid input"<<endl;
        }else{
            for(const auto& s:students)
            cout<<"student:"<<s.name<<",Grade:"<<s.grade<<endl;
            for(const auto&t:teachers)
            cout<<"Teacher:"<<t.name<<",subject:"<<t.subject<<endl;
        }
        return 0;
        
    }
}