#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int maxn = 110; struct ST { char name[25]; char sex[10]; int r1, r2; }; ST s[maxn], t[maxn]; int maxr1, maxr2; bool cmp(ST a, ST b) { return a.r1*1.0/maxr1*90+a.r2*1.0/maxr2*210 > b.r1*1.0/maxr1*90+b.r2*1.0/maxr2*210; } int main() { int T; cin >> T; while (T--) { int n, m; scanf("%d%d", &n, &m); maxr1 = 0, maxr2 = 0; for (int i = 0; i < n; ++i) { scanf("%s%s%d%d", s[i].name, s[i].sex, &s[i].r1, &s[i].r2); maxr1 = max(maxr1, s[i].r1); maxr2 = max(maxr2, s[i].r2); } sort(s, s+n, cmp); int k = 0, mm = 0; for (int i = 0; i < n; ++i) if (s[i].sex[0] == 'f') { t[k++] = s[i]; mm++; for (int j = i+1; j < n; ++j) s[j-1] = s[j]; n--; break; } for (int i = 0; i < m-k; ++i) t[mm++] = s[i]; sort(t, t+mm, cmp); printf("The member list of Shandong team is as follows:\n"); for (int i = 0; i < mm; ++i) printf("%s\n", t[i].name); } return 0; }