#include <iostream>
#include <cctype>
using namespace std;
void ChuanHoa(string &str) {
str[0] = toupper(str[0]);
for (int i = 1; i < str.size(); i++)
str[i] = tolower(str[i]);
}
void InHoa(string &str) {
for (char &c : str)
c = toupper(c);
}
int main() {
int T; cin >> T;
cin.ignore();
while (T--) {
string S;
getline(cin, S);
string name[100+5];
int nameCnt = 0;
string tmp;
for (char ch : S) {
if (isalpha(ch)) {
tmp += ch;
} else if (!tmp.empty()) {
name[nameCnt++] = tmp;
tmp = "";
}
}
if (!tmp.empty())
name[nameCnt++] = tmp;
if (nameCnt == 0) continue;
for (int i = 1; i < nameCnt; i++) {
ChuanHoa(name[i]);
cout << name[i];
if (i != nameCnt - 1)
cout << ' ';
}
InHoa(name[0]);
cout << ", " << name[0];
cout << '\n';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2N0eXBlPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBDaHVhbkhvYShzdHJpbmcgJnN0cikgewogICAgc3RyWzBdID0gdG91cHBlcihzdHJbMF0pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBzdHIuc2l6ZSgpOyBpKyspCiAgICAgICAgc3RyW2ldID0gdG9sb3dlcihzdHJbaV0pOwp9Cgp2b2lkIEluSG9hKHN0cmluZyAmc3RyKSB7CiAgICBmb3IgKGNoYXIgJmMgOiBzdHIpCiAgICAgICAgYyA9IHRvdXBwZXIoYyk7Cn0KCmludCBtYWluKCkgewogICAgaW50IFQ7IGNpbiA+PiBUOwogICAgY2luLmlnbm9yZSgpOwoKICAgIHdoaWxlIChULS0pIHsKICAgICAgICBzdHJpbmcgUzsKICAgICAgICBnZXRsaW5lKGNpbiwgUyk7CgogICAgICAgIHN0cmluZyBuYW1lWzEwMCs1XTsKICAgICAgICBpbnQgbmFtZUNudCA9IDA7CiAgICAgICAgc3RyaW5nIHRtcDsKCiAgICAgICAgZm9yIChjaGFyIGNoIDogUykgewogICAgICAgICAgICBpZiAoaXNhbHBoYShjaCkpIHsKICAgICAgICAgICAgICAgIHRtcCArPSBjaDsKICAgICAgICAgICAgfSBlbHNlIGlmICghdG1wLmVtcHR5KCkpIHsKICAgICAgICAgICAgICAgIG5hbWVbbmFtZUNudCsrXSA9IHRtcDsKICAgICAgICAgICAgICAgIHRtcCA9ICIiOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICghdG1wLmVtcHR5KCkpCiAgICAgICAgICAgIG5hbWVbbmFtZUNudCsrXSA9IHRtcDsKCiAgICAgICAgaWYgKG5hbWVDbnQgPT0gMCkgY29udGludWU7CiAgICAgICAgCiAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPCBuYW1lQ250OyBpKyspIHsKICAgICAgICAgICAgQ2h1YW5Ib2EobmFtZVtpXSk7CiAgICAgICAgICAgIGNvdXQgPDwgbmFtZVtpXTsKICAgICAgICAgICAgaWYgKGkgIT0gbmFtZUNudCAtIDEpCiAgICAgICAgICAgICAgICBjb3V0IDw8ICcgJzsKICAgICAgICB9CiAgICAgICAgSW5Ib2EobmFtZVswXSk7CiAgICAgICAgY291dCA8PCAiLCAiIDw8IG5hbWVbMF07CiAgICAgICAgY291dCA8PCAnXG4nOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==