#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int hum(const string &s, int pos, const string obj){
    int ret = 0;
    for (int i = 0; i < obj.size(); i++){
        if (s[i+pos] != obj[i]) ret++;
    }
    return ret;
}

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; i++){
        string s;
        cin >> s;
        int ans1 = s.size();
        for (int j = 0; j <= s.size() - 11; j++){
            int tmp = hum(s, j, "good");
            for (int k = j+4; k <= s.size() -7; k++){
                int tmp1 = hum(s, k, "problem");
                ans1 = min(ans1, tmp+tmp1);
            }
        }
        cout << ans1 << endl;
    }
}