#include using namespace std; int main() { int T; cin >> T; while (T--) { string S; int N; cin >> S; N = S.size(); string A = "good", B = "problem"; int ans = 1e5; for (int i = 0; i < N; i++) { for (int j = i + 4; j < N - 6; j++) { int tmp = 0; for (int x = 0; x < 4; x++) { if (S[i + x] != A[x]) tmp++; } for (int x = 0; x < 7; x++) { if (S[j + x] != B[x]) tmp++; } ans = min(ans, tmp); } } cout << ans << endl; } }