#include<bits/stdc++.h>
using namespace std;
struct Actress{
private:
string _name;
char _type;
int _skilled;
public:
Actress(string n=string(), char t=char(), int s=int())
:_name(n),
_type(t),
_skilled(s){}
string& name(){
return _name;
}
char& type(){
return _type;
}
int& skilled(){
return _skilled;
}
};
int main() {
vector<Actress> survivor, hunter;
int sn, hn;
cin>>sn>>hn;
for(int i=0; i<sn+hn; i++){
string s;
char c;
int x;
cin>>s>>c>>x;
if(c=='S'){
survivor.push_back(Actress(s, c, x));
}
else{
hunter.push_back(Actress(s, c, x));
}
}
sort(survivor.begin(), survivor.end(),
[&](Actress _aa, Actress _bb)->bool{
return _aa.skilled()<_bb.skilled();
});
sort(hunter.begin(), hunter.end(),
[&](Actress _aa, Actress _bb)->bool{
return _aa.skilled()<_bb.skilled();
});
int i=2;
while(hunter.size()>1&&i>0){
hunter.pop_back();
i--;
}
i=5;
while(survivor.size()>4&&i>0){
survivor.pop_back();
i--;
}
cout<<hunter.back().name()<<endl;
for(i=0; i<4; i++){
cout<<survivor.back().name()<<endl;
survivor.pop_back();
}
return 0;
}
(segment fault with invailld memory)