# -*- coding: utf-8 -*- def check(s1, s2): c = 0 for i in range(len(s1)): if s1[i]!=s2[i]: c += 1 return c t = int(input()) index_good = 0 index_problem = 0 for i in range(t): s = input() cost = 100 for j in range(len(s)): for k in range(j+4, len(s)-6, 1): if cost > check(s[j:j+4], 'good')+check(s[k:k+7], 'problem'): cost = check(s[j:j+4], 'good')+check(s[k:k+7], 'problem') index_good = j index_problem = k # for j in range(len(s)): # if s[j:j+7]=='problem': # if j < index_good: # cost += 1 print(cost)