import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner koko = new Scanner(System.in); int t = koko.nextInt(); String[] s = new String[t]; for(int i=0; i<t; i++){ s[i]=koko.next(); char[] sc = s[i].toCharArray(); int len = s[i].length(); int[] count = new int[10000]; int co = 0; for(int j=0; j<len-10; j++){ int n=11; if(sc[j]=='g'){ n--; } if(sc[j+1]=='o'){ n--; } if(sc[j+2]=='o'){ n--; } if(sc[j+3]=='d'){ n--; } for(int k=j+4; k<len-6; k++){ int kcount = n; if(sc[k]=='p'){ kcount--; } if(sc[k+1]=='r'){ kcount--; } if(sc[k+2]=='o'){ kcount--; } if(sc[k+3]=='b'){ kcount--; } if(sc[k+4]=='l'){ kcount--; } if(sc[k+5]=='e'){ kcount--; } if(sc[k+6]=='m'){ kcount--; } count[co++]=kcount; } } int[] rcount = new int[co]; for(int m=0; m<co; m++){ rcount[m]=count[m]; } Arrays.sort(rcount); System.out.println(rcount[0]); } } }