import java.lang.StringBuilder fun main(args: Array) { val n = readLine()!!.toInt() val ans = StringBuilder() for(i in 1..n) { ans.appendLine(solve(readLine()!!)) } print(ans.toString()) } fun solve(s:String):Int { val w1 = "good" val w2 = "problem" var w2Index:Int? = null var w2Count = 100 var ans = s.length for(i in (0..(s.length-w1.length-w2.length))) { val w1Conv = diff(s.drop(i).take(w1.length), w1) if(w2Index?:0 >=i+w1.length) { ans = Math.min(ans, w1Conv + w2Count) continue } var convCount = 100 for(j in (i+w1.length..s.length - w2.length)) { val tmp = diff(s.drop(j).take(w2.length), w2) if(convCount >= tmp) { w2Index = j w2Count = tmp convCount = tmp } } ans = Math.min(ans, w1Conv + w2Count) } return ans } fun diff(s1:String, s2:String):Int { return s1.indices.count { s1[it] != s2[it] } }