#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<pair<string,string>> vec;
bool cmp(pair<string ,string> a,pair<string ,string> b){
    string s1= a.second,s2=b.second;
    int pos1=s1.find('(');
    int pos2=s2.find('(');
    double t1=atof(s1.substr(0,pos1).c_str());
    double t2=atof(s2.substr(0,pos2).c_str());
    return t1<t2;
}
int main() {
    string name,date,time,t;
    while(getline(cin,name)){
        
        int p=name.find_last_of(' ');
        t=name.substr(p+1);
        string inform=name.substr(0,p+1);
        vec.push_back(pair(inform,t));
    }
    stable_sort(vec.begin(),vec.end(),cmp);
    for(auto it:vec){
        cout<<it.first<<it.second<<endl;
    }
}
// 64 位输出请用 printf("%lld")