import java.util.Scanner; public class GO { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String s=null; String good ="good",problem="problem"; for (int t = 0; t < T; t++) { int ans = 1<<29; s = sc.next(); for (int i = 0; i < s.length(); i++) { for (int j = i+good.length(); j <= s.length()-problem.length(); j++) { int sum = 0; sum = len(good,s.substring(i,i+good.length())) + len(problem,s.substring(j,j+problem.length())); ans = Math.min(ans, sum); } } System.out.println(ans); } } static int len(String s,String t){ int res = 0; for (int i = 0; i < s.length(); i++) { res += s.charAt(i)==t.charAt(i)?0:1; } return res; } }