def solution(): C = list(input().strip()) result = i = cnt = 0 lookup = [False]*len(C) for i in range(len(C)): if lookup[i]: continue lookup[i] = True left = i while not lookup[(left-1)%len(C)] and C[(left-1)%len(C)] == C[i]: lookup[(left-1)%len(C)] = True left -= 1 right = i while not lookup[(right+1)%len(C)] and C[(right+1)%len(C)] == C[i]: lookup[(right+1)%len(C)] = True right += 1 result += (right-left+1)//2 cnt += 1 return result if cnt >= 2 else (len(C)+1)//2 for case in range(int(input())): print('Case #%d: %s' % (case+1, solution()))