#include using namespace std; bool fake_wall(const string& X) { int n = (int)X.size(); int i = 0; while (i < n && X[i] == 'o') i++; int gCount = 0; while (i < n && X[i] == 'g') { gCount++; i++; } int midO = 0; while (i < n && X[i] == 'o') { midO++; i++; } int dCount = 0; while (i < n && X[i] == 'd') { dCount++; i++; } while (i < n && X[i] == 'o') i++; return i == n && gCount >= 1 && dCount >= 1 && midO >= 3; } 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'; } }