using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static private Magatro M = new Magatro(); static private void Main(string[]args) { M.Scan(); M.Solve(); } } public class Scanner { private string[] S; private int Index; private char Separator; public Scanner(char separator = ' ') { Index = 0; Separator = separator; } private string[] Line() { return Console.ReadLine().Split(Separator); } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } public class Magatro { private int T; private Scanner Sc = new Scanner(); private const string good= "good"; private const string problem = "problem"; public void Scan() { T = Sc.NextInt(); } public void Solve() { for(int i = 0; i < T; i++) { string S = Sc.Next(); Console.WriteLine(Anser(S)); } } private int Anser(string s) { int result = int.MaxValue; for(int i = 0; i <= s.Length - good.Length - problem.Length; i++) { for(int j = i + 4; j <= s.Length - problem.Length; j++) { result = Math.Min(result, Change(s,i,good) + Change(s,j,problem)); } } return result; } private int Change(string s,int index,string b) { int result = b.Length; if (s.Length-index < b.Length) throw new Exception(); for(int i = 0; i < b.Length; i++) { if (s[index+i] == b[i]) result--; } return result; } }