#include #include #include #include #include #include #include #include #include using namespace std; struct person { int y; char name[110]; }human[110]; bool cmp(person a, person b){ return a.y > b.y; } int main() { int t; scanf("%d", &t); while(t--){ int n; scanf("%d", &n);getchar(); memset(human, 0, sizeof(human)); for(int i = 0; i < n; i++){ char temp[200] = {'\0'}; gets(temp); int len = strlen(temp); int num = 0; for(int j = len - 4; j <= len - 1; j++){ num *= 10; num += temp[j] - '0'; } human[i].y = num; for(int j = len - 6; j >= 0; j--){ human[i].name[j] = temp[j]; } } sort(human, human + n, cmp); for(int i = 0; i < n; i++){ puts(human[i].name); //cout << human[i].y << endl; } } return 0; }