#include using namespace std; bool is_good(const string& s) { return s.find("good") != string::npos; } 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(); bool ok = true; for (int i = 0; i < n; i++) { if (S[i] == T[i]) continue; int pos = -1; for (int j = i + 1; j < n; j++) { if (S[j] == T[i]) { pos = j; break; } } if (pos == -1) { ok = false; break; } while (pos > i) { string U = S; swap(U[pos - 1], U[pos]); if (is_good(U)) { // それっぽく別候補を探すが、実は不完全 int alt = -1; for (int j = pos + 1; j < n; j++) { if (S[j] == T[i]) { alt = j; break; } } if (alt == -1) { ok = false; break; } pos = alt; continue; } S = U; pos--; } if (!ok) break; } cout << (ok && S == T ? "Yes" : "No") << '\n'; } return 0; }