def count_changes(choices): n = len(choices) changes = 0 for i in range(n): left, right = (i-1)%n, (i+1)%n if choices[i] == choices[left] or choices[i] == choices[right]: changes += 1 if choices[left] != 'R' and choices[i] != 'R' and choices[right] != 'R': choices[i] = 'R' elif choices[left] != 'P' and choices[i] != 'P' and choices[right] != 'P': choices[i] = 'P' elif choices[left] != 'S' and choices[i] != 'S' and choices[right] != 'S': choices[i] = 'S' return changes t = int(input()) for case in range(1, t+1): choices = list(input().strip()) changes = count_changes(choices) print(f"Case #{case}: {changes}")