Paradox Sort (Small)

Find the lexicographically smallest candy order whose sequential pairwise elimination leaves candy A standing, or report IMPOSSIBLE.

Medium6GraphBrute forceSimulationNo attempts yetTime limit5sMemory limit512 MB

Problem

Vlad likes candy. You have a bag of distinct candies, and you are going to let Vlad keep exactly one of them. You first choose an order for the candies, then hand them to Vlad one at a time in that order. Starting with the second candy, Vlad compares the candy he just received to the one he is holding, keeps the one he prefers, and throws the other away. A candy that has been thrown away never comes back.

You might expect Vlad to finish holding his favorite candy no matter which order you choose. That is not what happens. Vlad does not necessarily have a favorite candy. His choice between any two candies is known, but those choices do not have to come from a single ranking. He may pick Orange over Lemon, Banana over Orange, and Lemon over Banana.

There is a particular candy AA that you want Vlad to finish with. Given Vlad's preference for every pair of candies, decide whether some order leaves Vlad holding candy AA. If one exists, find the lexicographically smallest such order.

Input

The first line contains the number of test cases, TT. TT test cases follow.

Each test case starts with a line containing two integers NN and AA separated by one space. NN is the number of candies and AA is the number of the candy you want Vlad to finish with. The candies are numbered from 00 to N1N-1.

The next NN lines each contain NN characters. Character jj of line ii is Y if Vlad prefers candy ii to candy jj, N if he prefers candy jj to candy ii, and - if i=ji = j. Lines and characters are both numbered from 00. For iji \neq j, character jj of line ii differs from character ii of line jj.

Limits

  • 1T1001 \le T \le 100
  • 1N101 \le N \le 10
  • 0AN10 \le A \le N-1

Output

For each test case, print Case #x: followed by the answer. x is the test case number, starting at 11.

If no order leaves Vlad holding candy AA, print IMPOSSIBLE. Otherwise print the lexicographically smallest such order as candy numbers separated by one space. Orders are compared lexicographically as sequences of candy numbers.