#define _USE_MATH_DEFINES #include #include #include #include #include #include //#include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// int ans[100000]; bool check(string str){ int a,b; a = str.find("good"); if(a == -1){ return false; } b = str.find("problem",a); if( b == -1){ return false; } return true; } int ter1,termin1; int ngit,ngit2; int ngcount,ngcount2; int ser(string str,string ter,string ng){ //strからter作る ngがあってはだめ int ans=ter.size()+1,tans; ans = min(ans,termin1); for(unsigned int i=ter1; i+4 <= str.size(); ++i){ tans = 0; for(unsigned int len=0;len < ter.size() && i+len < str.size() ; ++len){ if( str[i+len] != ter[len]){ ++tans; } } ans = min(ans,tans); ++ter1; termin1 = min(termin1,ans); } //// int it = ngit; int temp; int count = ngcount; ans += ngcount; for(;;){ temp = str.find(ng,it); if(temp == -1){ break; } it = temp+1; ++count; ++ans; } ngit = it; ngcount = count; return ans; } int ser2(string str,string ter,string ng){ //strからter作る ngがあってはだめ int ans=ter.size()+1,tans; int temp,it=0; int count = 0; string tStr; for(unsigned int i=0;i+7<=str.size();++i){ tans = 0; //0,i-1までにng tStr = str.substr(0,i); it = 0; for(;;){ temp = tStr.find(ng,it); if(temp == -1){ break; } it = temp + 1; ++tans; } for(unsigned int len=0;len < ter.size() && i+len < str.size() ; ++len ){ if( str[i+len] != ter[len]){ ++tans; } } ans = min(ans,tans); } return ans; } int solve(string str){ ter1 = 0; termin1 = 4; ngit=0; ngit2 =0; ngcount=0; ngcount2=0; //goodp roble m int ans = 12,tans; string Astr,Bstr; for(unsigned int i=0;i+11<=str.size();++i){ Astr = str.substr(0,i+4); tans = ser(Astr, "good","problem"); if(ans <= tans)continue; Bstr = str.substr(i+4,str.size()-i-4 ); tans += ser2(Bstr,"problem","good"); ans = min(ans,tans); } return ans; } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// //cout << setprecision(16);// int T; cin>>T; string str; rep(i,T){ cin>>str; ans[i] = solve(str); } rep(i,T){ P(ans[i]); } return 0; }