#include using namespace std; const int INF = 1 << 20; const string good = "good"; const string problem = "problem"; vector countDiff(const string& S, const string& target){ const int n = S.size(); const int m = target.size(); vector res(n, INF); for(int i=0;i<=n-m;i++){ int diff = 0; for(int j=0;j=0;i--){ afterProblem[i] = min(afterProblem[i+1], afterProblem[i]); } vector mustDelete(n, 0); for(int i=0;i n){ break; } int cost = goodDiff[i]; if(i - 1 >= 0){ cost += mustDelete[i-1]; } cost += afterProblem[i+good.size()]; res = min(res, cost); } return res; } int main(){ int T; cin >> T; while(T--){ string S; cin >> S; cout << solve(S) << endl; } return 0; }