#include <iostream>
#include <string>
using namespace std;
string reverse(string::iterator& it)
{
char head = *(it++);
if (head == 'b' || head == 'w')
return string(1, head);
string upperLeft = reverse(it);
string upperRight = reverse(it);
string lowerLeft = reverse(it);
string lowerRight = reverse(it);
return "x" + lowerLeft + lowerRight + upperLeft + upperRight;
}
int main(void)
{
int C; cin >> C; while(C--)
{
string picture;
cin >> picture;
string::iterator it = picture.begin();
cout << reverse(it) << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPiAKI2luY2x1ZGUgPHN0cmluZz4gCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RyaW5nIHJldmVyc2Uoc3RyaW5nOjppdGVyYXRvciYgaXQpCnsKCWNoYXIgaGVhZCA9ICooaXQrKyk7CglpZiAoaGVhZCA9PSAnYicgfHwgaGVhZCA9PSAndycpCgkJcmV0dXJuIHN0cmluZygxLCBoZWFkKTsKCXN0cmluZyB1cHBlckxlZnQgPSByZXZlcnNlKGl0KTsKCXN0cmluZyB1cHBlclJpZ2h0ID0gcmV2ZXJzZShpdCk7CglzdHJpbmcgbG93ZXJMZWZ0ID0gcmV2ZXJzZShpdCk7CglzdHJpbmcgbG93ZXJSaWdodCA9IHJldmVyc2UoaXQpOwoJCglyZXR1cm4gIngiICsgbG93ZXJMZWZ0ICsgbG93ZXJSaWdodCArIHVwcGVyTGVmdCArIHVwcGVyUmlnaHQ7Cn0gCgppbnQgbWFpbih2b2lkKQp7IAoJaW50IEM7IGNpbiA+PiBDOyB3aGlsZShDLS0pCgl7CgkJc3RyaW5nIHBpY3R1cmU7CgkJY2luID4+IHBpY3R1cmU7CgkJc3RyaW5nOjppdGVyYXRvciBpdCA9IHBpY3R1cmUuYmVnaW4oKTsgCgkJY291dCA8PCByZXZlcnNlKGl0KSA8PCBlbmRsOyAKCX0KCXJldHVybiAwOyAKfQo=