#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(void)
{
int n;
cin >> n;
cin.ignore(); //입력 버퍼 지워주기(cin 사용 후 \n가 입력버퍼에 남아있어서 getline에서 입력 처리가 된다.)
while (n--)
{
string arr;
getline(cin, arr); //띄어쓰기 포함한 문자열 입력
arr += ' '; //문장의 끝도 변화시키기 위함
stack<char> s;
for (char ch : arr) //배열 arr의 값을 순차적으로 ch에 저장
{
if (ch == ' ') //문장의 중간 혹은 끝
{
while (!s.empty()) //스택이 비워질 때까지
{
cout << s.top();//문자 출력
s.pop();
}
cout << ch; //띄어쓰기 출력
}
else //띄어쓰기가 입력이 안될 때
s.push(ch);
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3RhY2s+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4odm9pZCkKewoJaW50IG47CgljaW4gPj4gbjsKCWNpbi5pZ25vcmUoKTsJCQkJLy/snoXroKUg67KE7Y28IOyngOybjOyjvOq4sChjaW4g7IKs7JqpIO2bhCBcbuqwgCDsnoXroKXrsoTtjbzsl5Ag64Ko7JWE7J6I7Ja07IScIGdldGxpbmXsl5DshJwg7J6F66ClIOyymOumrOqwgCDrkJzri6QuKQoJd2hpbGUgKG4tLSkKCXsKCQlzdHJpbmcgYXJyOwoJCWdldGxpbmUoY2luLCBhcnIpOwkJLy/rnYTslrTsk7DquLAg7Y+s7ZWo7ZWcIOusuOyekOyXtCDsnoXroKUKCQlhcnIgKz0gJyAnOwkJCQkvL+usuOyepeydmCDrgZ3rj4Qg67OA7ZmU7Iuc7YKk6riwIOychO2VqAoJCXN0YWNrPGNoYXI+IHM7CgoJCWZvciAoY2hhciBjaCA6IGFycikJCS8v67Cw7Je0IGFycuydmCDqsJLsnYQg7Iic7LCo7KCB7Jy866GcIGNo7JeQIOyggOyepQoJCXsKCQkJaWYgKGNoID09ICcgJykJCQkvL+usuOyepeydmC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