#include using namespace std; bool is_good(const string& s) { return s.find("good") != string::npos; } int score(const string& s, const string& t) { int res = 0; for (int i = 0; i < (int)s.size(); i++) { if (s[i] != t[i]) res++; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int Q; cin >> Q; while (Q--) { string S, T; cin >> S >> T; vector cntS(3, 0), cntT(3, 0); for (char c : S) { if (c == 'd') cntS[0]++; else if (c == 'o') cntS[1]++; else cntS[2]++; } for (char c : T) { if (c == 'd') cntT[0]++; else if (c == 'o') cntT[1]++; else cntT[2]++; } if (cntS != cntT) { cout << "No\n"; continue; } int n = (int)S.size(); int limit = 20 * n + 100; bool ok = false; for (int step = 0; step < limit; step++) { if (S == T) { ok = true; break; } int curScore = score(S, T); int bestScore = curScore; int bestPos = -1; for (int i = 0; i + 1 < n; i++) { if (S[i] == S[i + 1]) continue; string U = S; swap(U[i], U[i + 1]); if (is_good(U)) continue; int sc = score(U, T); if (sc < bestScore) { bestScore = sc; bestPos = i; } } if (bestPos == -1) { break; } swap(S[bestPos], S[bestPos + 1]); } cout << (ok ? "Yes" : "No") << '\n'; } return 0; }