import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto t = readln.chomp.to!size_t; foreach (_; 0..t) calc(); } void calc() { auto s = readln.chomp, sl = s.length; auto dg = new int[](sl-10), dp = new int[](sl-10); foreach (i; 0..sl-10) { dg[i] = dist(s[i..i+4], "good"); dp[i] = dist(s[i+4..i+11], "problem"); } auto fp = s.indexOf("problem"); foreach (i; 1..sl-10) { dg[i] = min(dg[i-1], dg[i]); dp[$-i-1] = min(dp[$-i], dp[$-i-1]); } dg[] += dp[]; auto r = int.max; foreach (i; 0..sl-10) { if (r > dg[i]) { r = dg[i]; if (fp >= 0 && i > fp) { ++r; } } } writeln(r); } int dist(string s, string t) { return s.zip(t).count!"a[0] != a[1]".to!int; }