#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 solve(string str){ //goodp roble m int LenA,LenB; int minLA = 5,minLApos=-1; int minLB = 8,minLBpos=-1; int ans=12,tans; for(int i=0;i<=str.size()-11;++i){ LenA = 0; if(str[i ] != 'g')LenA++; if(str[i+1] != 'o')LenA++; if(str[i+2] != 'o')LenA++; if(str[i+3] != 'd')LenA++; if(ans <= LenA) continue; if( i+4 <= minLBpos ){ tans = LenA + minLB; ans = min(ans,tans); if(ans == 0){ break; } continue; } for(int j=i+4; j<=str.size()-7; ++j){ LenB = 0; if(str[j ] != 'p')LenB++; if(str[j+1] != 'r')LenB++; if(str[j+2] != 'o')LenB++; if(str[j+3] != 'b')LenB++; if(str[j+4] != 'l')LenB++; if(str[j+5] != 'e')LenB++; if(str[j+6] != 'm')LenB++; if( minLBpos < i+4 || LenB < minLB){ minLB = LenB; minLBpos = j; } tans = LenA+LenB; ans = min(ans,tans); if(LenB == 0){ break; } if(ans == 0){ break; } } if(ans == 0){ break; } } 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; }