import re import itertools def solve(S): words_original = [c for c in 'goodproblem'] for i in range(12): for pos in itertools.combinations(range(11), i): words = words_original[:] for p in pos: words[p] = '.' pattern = ''.join(words[:4] + ['.*'] + words[4:]) result = re.search(pattern, S) if result: return i if __name__ == '__main__': T = int(input()) for t in range(T): print(solve(input()))