n = int(input()) good = "good" prob = "problem" def func(moji): good_index = 0 good_c = 4 for i in range(len(moji)-7): tmp = 4 for k in range(4): if moji[i+k] == good[k]: tmp -= 1 if tmp < good_c: good_index = i good_c = tmp prob_index = good_index+4 prob_c = 7 for j in range(len(moji)-prob_index-7+1): tmp = 7 for k in range(7): if moji[prob_index+j+k] == prob[k]: tmp -= 1 prob_c = min(prob_c, tmp) print(good_c+prob_c) for i in range(n): func(input())