#include using namespace std; bool fake_wall(const string& X) { bool hasG = false, hasD = false; bool seenD = false; bool orderOK = true; for (char c : X) { if (c == 'o') continue; if (c == 'd') { hasD = true; seenD = true; } else { hasG = true; if (seenD) orderOK = false; } } if (!hasG || !hasD || !orderOK) return false; int lastG = -1; int firstD = (int)X.size(); for (int i = 0; i < (int)X.size(); i++) { if (X[i] == 'g') lastG = i; if (X[i] == 'd') { firstD = i; break; } } int betweenO = 0; for (int i = lastG + 1; i < firstD; i++) { if (X[i] == 'o') betweenO++; } // 嘘: 本当は >= 3 return betweenO >= 4; } 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), cntT(3); 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 << (fake_wall(S) == fake_wall(T) ? "Yes" : "No") << '\n'; } }