#include using namespace std; bool is_good(const string& s) { return s.find("good") != string::npos; } string normalize(string s) { int n = (int)s.size(); // 嘘: 局所的に辞書順が小さくなる swap を繰り返すだけ // 文字順は d < g < o として適当に決めている for (int step = 0; step < 50 * n + 100; step++) { bool changed = false; for (int i = 0; i + 1 < n; i++) { if (s[i] <= s[i + 1]) continue; string t = s; swap(t[i], t[i + 1]); if (is_good(t)) continue; s = t; changed = true; break; } if (!changed) break; } return s; } 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; } cout << (normalize(S) == normalize(T) ? "Yes" : "No") << '\n'; } return 0; }