using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProgrammingContest { class MainClass { Scanner sc; static void Main(string[] args) { new MainClass().solve(); } const bool DEBUG = false; // must check!! void solve() { if (DEBUG) { string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt"; sc = new Scanner(new System.IO.StreamReader(inFilePath)); } else { sc = new Scanner(); } int t = sc.NextInt; StringBuilder ans = new StringBuilder(); for (int i = 0; i < t; i++) { ans.AppendLine(calc(sc.Next).ToString()); } Console.Write(ans); } const string good = "good"; const string problem = "problem"; int calc(string s) { int L = s.Length; int res = (int)1e9; for (int i = 0; i < L - good.Length - problem.Length + 1; i++) { int pre = 0; for (int j = 0; j < good.Length; j++) { if (s[i + j] != good[j]) { pre++; } } int pre2 = (int)1e9; for (int j = i + good.Length; j < L - problem.Length + 1; j++) { int pre3 = 0; for (int k = 0; k < problem.Length; k++) { if (s[j + k] != problem[k]) { pre3++; } } pre2 = Math.Min(pre2, pre3); } res = Math.Min(res, pre + pre2); } return res; } } class Scanner { Queue buffer; char[] sep; System.IO.TextReader reader; public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue(); this.sep = new char[] { ' ' }; this.reader = (reader == null ? Console.In : reader); } private void checkBuffer() { if (this.buffer.Count == 0) { String[] sreArray = this.reader.ReadLine().Split(this.sep); foreach (String elStr in sreArray) { this.buffer.Enqueue(elStr); } } } public String Next { get { this.checkBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool isEmpty { get { this.checkBuffer(); return this.buffer.Count == 0; } } } }