
#include <iostream>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
using std::string;
using std::reverse;
string processZ(const string& s) {
string result;
for (char c : s) {
if (c == 'Z') {
if (!result.empty()) {
result.pop_back();
}
} else {
result.push_back(c);
}
}
return result;
}
string processR(const string& t) {
string ans;
bool reverseFlag = false;
for (char c : t) {
if (c == 'R') {
reverseFlag = !reverseFlag;
} else {
if (reverseFlag) {
ans.insert(ans.begin(), c);
} else {
ans.push_back(c);
}
}
}
if (reverseFlag) {
reverse(ans.begin(), ans.end());
}
return ans;
}
void solve() {
string s;
cin >> s;
string afterZ = processZ(s);
string finalStr = processR(afterZ);
cout << finalStr << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
int l1, r1, l2, r2;
scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
int res = 0;
for (int i = l1; i <= r1; i++){
int r = min(i, r2);
for (int j = l2; j <= r; j++){
if (i % j == 0) res++;
}
}
cout << res << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int l1, r1, l2, r2;
scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
int m = min(r1, r2);
int res = 0;
for (int j = l2; j <= m; j++){
res += r1 / j - (l1 - 1) / j;
}
cout << res << endl;
return 0;
}
#美团笔试##笔试#