#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;} if(Cs.at('g'-'a') == 0 || Cs.at('d'-'a') == 0 || Cs.at('o'-'a') <= 1){yes(); continue;} int gs = 0,ds = 0,os = 0,del = 0; bool ng = false,end = false; for(int i=0; i Gs,Ds; for(int k=0; k= p2) ng = true; } if(ng) no(); else yes(); end = true; break; } } if(end) continue; if(ng){no(); continue;} t.erase(t.begin(),t.begin()+del); gs = 0,ds = 0,N = t.size(); for(auto c : t) gs += c=='g',ds += c=='d'; if(gs == 0){ for(int i=0; i<3; i++){ if(i == N) break; if(t.at(i) == 'd') ng = true; } if(ng) no(); else yes(); continue; } bool ok = false; for(int i=0; i 1 && t.at(i-2) == 'g') ok = true; break; } } if(ok) yes(); else no(); continue; } }