#include <stdio.h> #include <string.h> int main(void){ int in, n; scanf("%d", &n); for(in=0;in<n;in++){ char s[110]; const char good[] = "good"; const char problem[] = "problem"; int i; int hitGood[110]={0}; int hitProblem[110]={0}; int sLen, gLen,pLen; int ans = 99999; scanf("%s", s); sLen = strlen(s); gLen = strlen(good); pLen = strlen(problem); for(i=0;i<sLen;i++){ int j; int hit=0; for( j=0 ; j < gLen ; j++ ){ if(s[i+j] == '\0'){hit = 0; break;} if( good[j] == s[i+j]){ hit++; } } hitGood[i] = hit; hit = 0; for( j=0 ; j < pLen ; j++ ){ if(s[i+j] == '\0'){hit = 0; break;} if( problem[j] == s[i+j]){ hit++; } } hitProblem[i] = hit; } for(i=0;i<sLen;i++){ int j,cnt; int tmpMinCnt = 99999; cnt = (gLen-hitGood[i]); for(j=(i+gLen); (j+pLen-1)< sLen;j++){ int tmp = (pLen - hitProblem[j]); if( tmp < tmpMinCnt ){ tmpMinCnt = tmp; } } cnt = cnt + tmpMinCnt; if(cnt < ans ){ ans = cnt; } } printf("%d\n", ans); } return 0; }