#include using namespace std; int diff(string a,string b){ int ans = 0; for(int i = 0 ; i < a.size() ; i++) if( a[i] != b[i] ) ans++; return ans; } int f(string s){ vector good(s.size()+10,1e9); vector imos(s.size()+10,0); vector imos2(s.size()+10,0); good[4] = 4; int ans = 11; for(int i = 0 ; i+7 <= s.size() ; i++){ if(i) imos[i] += imos[i-1]; if(i) imos2[i] += imos2[i-1]; if(i) good[i] = min(good[i],good[i-1]); int need = diff(s.substr(i,7),"problem"); ans = min(ans, need + good[i] ); if( s.substr(i,7) == "problem" ) imos[i+7]++; if( s.substr(i,4) == "good" ) imos2[i+4]++; good[i+4] = min(good[i+4],imos2[i] + imos[i] + diff(s.substr(i,4),"good") ); } return ans; } int main(){ int n; cin >> n; for(int i = 0 ; i < n ; i++){ string s; cin >> s; cout << f(s) << endl; } }