for (char c : s) {
if (c == 'a') {
cnt++;
} else {
cnt = max(cnt - 1, 0ll);
}
}
23ccpc桂林GProblem - G - Codeforces
void solve() {
std::string s;
std::cin >> s;
int cnt = 0;
for (char c : s) {
if (c == '(') {
cnt++;
}
else {
cnt = std::max(cnt - 1, 0);
}
}
std::cout << (cnt ? "impossible" : s) << '\n';
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
using ll=long long;
void solve() {
std::string s;
std::cin >> s;
ll cnt = 0,x=0,y=0;
for (char c : s) {
if (c == 'a') {
cnt++;
x++;
}
else {
cnt = std::max(cnt - 1LL, 0LL);
y++;
}
}
if(s[0]=='b'||x!=y)cnt=1LL;
std::cout << (cnt ? "Bad" : "Good") << '\n';
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
int t=1;
while (t--) {
solve();
}
return 0;
}