import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.bitmanip, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto t = readln.chomp.to!int; foreach (_; 0..t) { auto s = readln.chomp; auto r = s.length; foreach (i; 0..s.length - (4 + 7) + 1) { auto h1 = hamiltonDistance("good", s[i..i + 4]); foreach (j; i + 4..s.length - 7 + 1) { auto h2 = hamiltonDistance("problem", s[j..j + 7]); if (h1 + h2 < r) r = h1 + h2; } } writeln(r); } } int hamiltonDistance(string a, string b) { return a.zip(b).count!("a[0] != a[1]").to!int; }