#include const double pi = 3.141592653589793238462643383279; using namespace std; //typedef //------------------------------------------ typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef pair PLL; typedef pair TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector VLL; typedef vector VVLL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a)*(a)) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,s,n) for(int i=s;i<(int)n;++i) #define REP(i,n) FOR(i,0,n) #define MOD 1000000007 #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; const double EPS = 1E-11; #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) //ここから編集 template struct SegmentTree{ vector node; int N; SegmentTree(int n){ N = 1; while(N < n) N*=2; node.resize(2*N-1, INT_MAX); } void update(int x, int val){ x += N-1; node[x] = val; while(x > 0){ x = (x-1)/2; node[x] = min(node[2*x+1], node[2*x+2]); } } // [a, b)について求める int getmin(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = N; if(r <= a || b <= l) return INT_MAX; if(a <= l && r <= b) return node[k]; int vl = getmin(a, b, 2*k+1, l, (l+r)/2); int vr = getmin(a, b, 2*k+2, (l+r)/2, r); return min(vl, vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int t; cin >> t; while(t--){ string s; cin >> s; SegmentTree seg(s.size()); string t = "problem"; for(int i=0; i= s.size()) break; string tmp = "good"; int cnt = 0; for(int j=0; j<4; j++){ if(tmp[j] != s[i+j]) cnt++; } ans = min(ans, cnt + seg.getmin(i+4, s.size())); } cout << ans << endl; } return 0; }