#include int main() { int N; int diff_g[128]; int diff_p[128]; int ans; std::string str; int count; std::cin >> N; for(int i = 0; i < N; ++i) { std::cin >> str; for(int j = 0; j < 128; ++j) { diff_g[j] = 10000; diff_p[j] = 10000; } for(int j = 0; j <= str.size()-4; ++j) { count = 0; if( str[j] != 'g' ) count += 1; if( str[j+1] != 'o' ) count += 1; if( str[j+2] != 'o' ) count += 1; if( str[j+3] != 'd' ) count += 1; diff_g[j] = count; } for(int j = 0; j <= str.size()-7; ++j) { count = 0; if( str[j] != 'p' ) count += 1; if( str[j+1] != 'r' ) count += 1; if( str[j+2] != 'o' ) count += 1; if( str[j+3] != 'b' ) count += 1; if( str[j+4] != 'l' ) count += 1; if( str[j+5] != 'e' ) count += 1; if( str[j+6] != 'm' ) count += 1; diff_p[j] = count; } ans = 10000; for(int j = 0; j <= str.size()-4-7; ++j) { for(int k = j+4; k <= str.size()-7; ++k) { ans = std::min(ans, diff_g[j]+diff_p[k]); } } std::cout << ans << std::endl; } return 0; }