#include #include #include void solve() { std::string s; std::cin >> s; int n = s.length(); std::vector gdp(n, 0); for (int i = 0; i + 4 <= n; ++i) { for (int j = 0; j < 4; ++j) { if (s[i + j] != "good"[j]) ++gdp[i]; } } std::vector pdp(n, 0); for (int i = 0; i + 7 <= n; ++i) { for (int j = 0; j < 7; ++j) { if (s[i + j] != "problem"[j]) ++pdp[i]; } } int ans = n; for (int j = 0; j + 7 <= n; ++j) { for (int i = 0; i + 4 <= j; ++i) { ans = std::min(ans, gdp[i] + pdp[j]); } } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int q; std::cin >> q; while (q--) solve(); return 0; }