#include<bits/stdc++.h>
using namespace std;
long long n,m;
string a[100015],b[100105],c;
char z;
bool ban[100105],bn[100105];
unsigned long long w[100100],s[100100],x,x1;
int main() {
ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=1; i<=n+m; i++) {
cin>>c;
cin>>z;
if(z=='S') {
a[i]=c;
cin>>w[i];
} else {
b[i]=c;
cin>>s[i];
}
}
for(int i=1; i<=5; i++) {
x=0;
for(int j=1; j<=n; j++) {
if(w[j]>x&&ban[j]==0) {
x=w[j];
x1=j;
}
}
ban[x1]=1;
}
for(int i=1; i<=2; i++) {
x=0;
for(int j=1; j<=n; j++) {
if(s[j]>x&&bn[j]==0) {
x=s[j];
x1=j;
}
}
bn[x1]=1;
}
x=0;
for(int i=1; i<=m; i++) {
if(s[i]>x&&bn[i]==0) {
x=s[i];
x1=i;
}
}
cout<<b[x1]<<endl;
for(int i=1; i<=4; i++) {
x=0;
for(int j=1; j<=n; j++) {
if(w[j]>=x&&ban[j]==0) {
x=w[j];
x1=j;
}
}
cout<<a[x1]<<endl;
ban[x1]=1;
}
return 0;
}
自己找不到错啊(QAQ)