#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; rep(_,T) { string S; cin >> S; string A = "good", B = "problem"; int N = S.size(), ans = 1e9; for(int i = 0; i + 10 < N; i++) { int cntA = 0; for(int k = 0; k < 4; k++) cntA += (S[i + k] != A[k]); for(int j = i + 4; j + 6 < N; j++) { int cntB = 0; for(int k = 0; k < 7; k++) cntB += (S[j + k] != B[k]); ans = min(ans, cntA + cntB); } } cout << ans << "\n"; } }