#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<pair<int, int> > vii;
struct P{
string name;
int a, d;
bool operator < (const P &p) const{
return name < p.name;
}
}p[10];
int main() {
int t, i, ca;
cin >> t;
for(ca=1;ca<=t;ca++){
for(i=0;i<10;i++)
cin>>p[i].name>>p[i].a>>p[i].d;
for(i=0;i<9;i++)
for(int j=0;j<9-i;j++)
if(p[j+1].a>p[j].a || (p[j+1].a==p[j].a&& (p[j+1].d<p[j].d || (p[j+1].d==p[j].d&&p[j+1].name<p[j].name) )))
swap(p[j], p[j+1]);
sort(p, p+5);
sort(p+5, p+10);
printf("Case %d:\n(",ca);
cout<<p[0].name;
for(i=1;i<5;i++) cout<<", "<< p[i].name;
cout<<")\n("<<p[5].name;
for(i=6;i<10;i++) cout<<", "<< p[i].name;
cout<<")"<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHN0ZDo6dmVjdG9yPGludD4gdmk7CnR5cGVkZWYgc3RkOjp2ZWN0b3I8cGFpcjxpbnQsIGludD4gPiB2aWk7CnN0cnVjdCBQewoJCXN0cmluZyBuYW1lOwoJCWludCBhLCBkOwoJCWJvb2wgb3BlcmF0b3IgPCAoY29uc3QgUCAmcCkgY29uc3R7CgkJCXJldHVybiBuYW1lIDwgcC5uYW1lOwoJCX0KCX1wWzEwXTsKaW50IG1haW4oKSB7CglpbnQgdCwgaSwgY2E7CgkKCWNpbiA+PiB0OwoJZm9yKGNhPTE7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ky 16 36
shamim 16 18
shadowcoder 12 9
muntasir 13 4
brokenarrow 16 16
emotionalblind 16 12
tanaeem 20 97
sameezahur 20 21
sohelh 18 9
jaan 17 86
sidky 16 36
shamim 16 18
shadowcoder 12 9
muntasir 13 4
brokenarrow 16 16
emotionalblind 16 12
tanaeem 20 97
Case 1:
(emotionalblind, jaan, sameezahur, sohelh, tanaeem)
(brokenarrow, muntasir, shadowcoder, shamim, sidky)
Case 2:
(emotionalblind, jaan, sameezahur, sohelh, tanaeem)
(brokenarrow, muntasir, shadowcoder, shamim, sidky)