import sequtils,strutils,math,algorithm type item = tuple[index,cost : int] var T = stdin.readline.parseInt s : string g = "good" p = "problem" for t in 1..T: s = stdin.readline var a : item cnt : int A = newSeq[item](0) ans : int = int.high for i in 0..(s.high - 6): cnt = 0 for j in 0..p.high: if s[i + j] != p[j]: cnt += 1 a = (i, cnt) A.add(a) A = A.sortedByIt(it.cost) for i in 0..(s.high - 3): cnt = 0 for j in 0..g.high: if s[i + j] != g[j]: cnt += 1 var flag : bool for a in A: if a.index > i + 3: cnt += a.cost flag = true break if flag: ans = min(ans, cnt) echo ans