def search(S, x): N = len(S) if x == 0: T = "good" st = 0 end = N - 10 else: T = "problem" st = 4 end = N - 6 ret = [0] * (N - 10) for i in range(st, end): tmp = 0 for j, t in enumerate(T): if S[i + j] == T[j]: tmp += 1 ret[i - st] = tmp return ret for _ in range(int(input())): S = input() N = len(S) - 10 A = search(S, 0) B = search(S, 1) max0 = 0 for i in range(N): max0 = max(max0, A[i] + max(B[i:])) print(11 - max0)