// Arup Guha
// 8/19/2015
// Solution to 2010 Fall Locals Problem: The Eternal Quest for Caffeine (Soda)

import java.util.*;

public class soda {

	final public static int IMPOSSIBLE = 10000;
	final public static int[] DX = {-1, 1};

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int floors = stdin.nextInt();
		int start = stdin.nextInt()-1;
		int parts = stdin.nextInt();
		int loop = 1;

		// Process all cases.
		while (floors != 0) {

			// Bit 0 = if there is a good soda on this floor.
			// Bits 1-P = if that part is on this floor.
			int[] machines = new int[floors];

			// Read in each floor, storing its appropriate bitmask.
			for (int i=0; i<floors; i++) {
				int n = stdin.nextInt();
				for (int j=0; j<n; j++)
					machines[i] |= (1 << stdin.nextInt());
				String soda = stdin.next();
				if (soda.equals("Y")) machines[i] |= 1;
			}

			int all = (1 << (parts+1)) - 1;

			// Trivial answer.
			if (machines[start] == all) System.out.println("Test case #"+loop+": 0");

			// Typical case.
			else {

				// Mask - bit 0 = do you have the soda, bits 1-parts parts we have, rest bits = cur floor.
				// ending mask is all ones 0-parts and the correct ending floor.

				// Where we start our search.
				int startMask = (machines[start] & (all-1)) | (start << (parts+1));
				int res = IMPOSSIBLE;

				// Set up BFS.
				HashMap<Integer,Integer> dist = new HashMap<Integer,Integer>();
				dist.put(startMask, 0);
				ArrayDeque<Integer> q = new ArrayDeque<Integer>();
				q.offer(startMask);

				// Run BFS.
				while (q.size() > 0) {

					// Get next item.
					int curMask = q.poll();
					int curFloor = (curMask >> (parts+1));
					int curDist = dist.get(curMask);

					// Got it!
					if (curMask == (all | (start << (parts+1)))) {
						res = curDist;
						break;
					}

					// Loop through moving both directions.
					for (int i=0; i<DX.length; i++) {

						// Only try if it's a valid floor.
						if (curFloor + DX[i] >= 0 && curFloor + DX[i] < floors) {

							// Add the parts on this floor.
							int thisMask = (machines[curFloor+DX[i]] & (all-1));
							int nextMask = curMask | thisMask;

							// Move to the new floor.
							nextMask = nextMask + DX[i]*(1 << (parts+1));

							// If we have all the parts and there's a soda on this floor, mark the soda.
							if (((nextMask & (all-1)) == all-1) && ((machines[curFloor+DX[i]] & 1) == 1)) nextMask |= 1;

							// Haven't been to this state before.
							if (!dist.containsKey(nextMask)) {
								dist.put(nextMask, curDist+1);
								q.offer(nextMask);
							}
						}
					}
				} // end bfs.

				// Print result.
				if (res == IMPOSSIBLE) 	System.out.println("Test case #"+loop+": Impossible");
				else					System.out.println("Test case #"+loop+": "+res);

			}

			// Get next case.
			System.out.println();
			floors = stdin.nextInt();
			start = stdin.nextInt()-1;
			parts = stdin.nextInt();
			loop++;
		}
	}
}