import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] good = "good".toCharArray(); int gLength = good.length; char[] problem = "problem".toCharArray(); int pLength = problem.length; int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t; i++) { char[] line = sc.next().toCharArray(); int min = Integer.MAX_VALUE; for (int j = 0; j <= line.length - gLength - pLength; j++) { int gCount = 0; for (int k = 0; k < gLength; k++) { if (good[k] != line[j + k]) { gCount++; } } for (int k = j + gLength; k <= line.length - pLength; k++) { int pCount = 0; for (int l = 0; l < pLength; l++) { if (problem[l] != line[k + l]) { pCount++; } } min = Math.min(min, gCount + pCount); } } sb.append(min).append("\n"); } System.out.print(sb); } }