// Arup Guha
// 4/7/2018
// Solution to 2018 Code Jam Qualification Problem: Save the Universe.

import java.util.*;

public class Solution {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// Process each case
		for (int loop=1; loop<=nC; loop++) {

			int val = stdin.nextInt();
			char[] s = stdin.next().toCharArray();

			// Can't do it.
			if (cnt(s,'S') > val)
				System.out.println("Case #"+loop+": IMPOSSIBLE");
			
			// The greedy solves it - always want to swap the most significant S.
			else
				System.out.println("Case #"+loop+": "+greedy(s,val));
		}
	}

	// Returns the number of times c is in s.
	public static int cnt(char[] s, char c) {
		int res = 0;
		for (int i=0; i<s.length; i++)
			if (s[i] == c)
				res++;
		return res;
	}

	// Solve for the fewest # of moves using a greedy (always takes the MSB and swaps it).
	public static int greedy(char[] s, int val) {

		int cur = getVal(s);
		int res = 0;

		while (cur > val) {
			update(s);
			cur = getVal(s);
			res++;
		}

		return res;
	}

	// Returns the current value of s.
	public static int getVal(char[] s) {
		int res = 0, curbit = 0;
		for (int i=0; i<s.length; i++) {
			if (s[i] == 'C') curbit++;
			else res += (1<<curbit);
		}
		return res;
	}

	// Swaps most significant 'S' adjacent to a 'C'.
	public static void update(char[] s) {
		int i = s.length-1;
		while (i > 0) {
			if (s[i] == 'S' && s[i-1] == 'C') {
				s[i] = 'C';
				s[i-1] = 'S';
				break;
			}
			i--;
		}
	}
}