#include using namespace std; bool solve(string s,string t){ set S; queue Q; Q.push(s),S.insert(s); int N = s.size(); bool ret = false; while(Q.size()){ auto now = Q.front(); Q.pop(); bool ng = false; for(int i=0; i<=N-4; i++) if(now.substr(i,4) == "good"){ng = true; break;} if(ng) continue; if(now == t) ret = true; for(int i=0; i> T; bool submit = true; if(T > 100000) submit = false; while(T--){ string s,t; if(!submit){ make(s,8),t = s; while(true){ shuffle(t.begin(),t.end(),mt); bool good = false; for(int i=0; i<=t.size()-4; i++) if(t.substr(i,4) == "good"){good = true; break;} if(good) continue; break; } } if(submit) cin >> s >> t; string memos = s,memot = t; auto no = [&]() -> void { cout << "No\n"; if(!submit && solve(memos,memot)){ cout << "Wrong No" << endl; cout << 1 << endl << memos << endl << memot << endl; exit(0); } }; auto yes = [&]() -> void { cout << "Yes\n"; if(!submit && !solve(memos,memot)){ cout << "Wrong Yes" << endl; cout << 1 << endl << memos << endl << memot << endl; exit(0); } }; int N = s.size(); vector Cs(26),Ct(26); for(auto c : s) Cs.at(c-'a')++; for(auto c : t) Ct.at(c-'a')++; if(Cs != Ct){no(); continue;} int gs = 0,ds = 0,os = 0,del = 0; bool ng = false; for(int i=0; i= N-1){yes(); continue;} char c1 = '-',c2 = '-',c3 = '-'; for(int i=N; i--;){ char c = t.at(i); if(c1 == 'o' && c2 == 'o' && c3 == 'd' && ds == 0){ng = true; break;} if(c == 'g') gs--; else if(c == 'd') ds--; c3 = c2,c2 = c1,c1 = c; } if(ng) no(); else yes(); } }