t = int(input()) for case in range(1, t+1): s = input().strip() n = len(s) # Count the number of each option count = {'R': 0, 'P': 0, 'S': 0} for c in s: count[c] += 1 # Find the option with the highest count max_count = max(count.values()) if max_count == n or max_count == n-1: # If all or all but one chose the same option, # we can't make any changes to avoid ties print(f"Case #{case}: 0") continue # Find the option that beats the one with the highest count if count['R'] == max_count: beat = 'P' elif count['P'] == max_count: beat = 'S' else: beat = 'R' # Count the number of times we need to change changes = 0 for i in range(n): if s[i] == beat: # We need to change this option to avoid a tie with one of its neighbors if i > 0 and s[i-1] == beat: # Change the current option to beat the other neighbor s = s[:i] + beat + s[i+1:] else: # Change the current option to beat the next neighbor s = s[:i] + (set('RPS') - set(s[i:i+2])).pop() + s[i+1:] changes += 1 print(f"Case #{case}: {changes}")