def goodploblem(string): len_s = len(string) good = [ 0 for i in range(len_s) ] plobrem = [ 0 for i in range(len_s) ] for i in range(len_s-10): good[i] = judge(string[i:i+4],"good") for i in range(4,len_s-6): plobrem[i] = judge(string[i:i+7],"problem") ans = 11 for i in range(len_s-10): ans = min(ans,(good[i]+min(plobrem[i+4:len_s-6]))) return ans def judge(instr,target): s = 0 t = len(target) for i in range(t): if target[i] == instr[i]: s += 1 return t-s n = int(input()) for i in range(n): print(goodploblem(input()))