#!/usr/bin/env python #coding:utf8 def read(): sList = [] for i in range(int(raw_input())): sList.append(raw_input()) return sList def work(sList): for s in sList: minV = 1 << 30 for i in range(len(s) - 3): for j in range(i + 4, len(s) - 6): cnt = 0 for idx, ch in enumerate("good"): cnt += s[i + idx] != ch for idx, ch in enumerate("problem"): cnt += s[j + idx] != ch minV = min(minV, cnt) print minV if __name__ == "__main__": work(read())