#include #include #include #include #include #include #include #include #include #include #include #include #include #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define DEBUG(x) cout<<#x<<": "< P; typedef long long int LL; const int INF=100000000; const string good="good",problem="problem"; string s[1000000]; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; REP(i,t) cin>>s[i]; REP(i,t){ int ans=INF; int n=SZ(s[i]); vector cg(n,INF); vector cp(n,INF); vector cgi(n); vector cpi(n); REP(j,n-4+1){ int c=0; REP(k,4){ if(s[i][j+k]!=good[k]) c++; } cg[j]=c; if(j!=0){ if(c==0) cgi[j]=cgi[j]+1; else cgi[j]=cgi[j]; }else{ if(c==0) cgi[j]=1; else cgi[j]=0; } } REP(j,n-7+1){ int c=0; REP(k,7){ if(s[i][j+k]!=problem[k]) c++; } cp[j]=c; if(j!=0){ if(c==0) cpi[j]=cpi[j-1]+1; else cpi[j]=cpi[j-1]; }else{ if(c==0) cpi[j]=1; else cpi[j]=0; } } vector co(7+1,0); FOR(i,4,n-7+1){ co[cp[i]]++; } int gmin=INF; int pmin; REP(i,8){ if(co[i]!=0){ pmin=i; break; } } REP(i,n-11+1){ gmin=min(gmin,cg[i]); //DEBUG(pmin); if(i<7){ ans=min(ans,gmin+pmin); }else{ //DEBUG(cpi[i-7]); ans=min(ans,gmin+pmin+cpi[i-7]); } co[cp[i+4]]--; if(cp[i+4]==pmin&&co[pmin]==0){ REP(l,8){ if(co[l]!=0){ pmin=l; break; } } } } cout<