Paradox Sort (Large)

Given every pairwise candy preference, decide whether some hand-over order leaves Vlad holding candy A and output the lexicographically smallest such order.

Medium7GraphDFSGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

Vlad likes candy. You have a bag of distinct candies and you are going to let him keep one of them. You choose an order for the candies, then hand them to Vlad one at a time. For each candy after the first, Vlad compares the candy he was holding with the one he just received, keeps the one he likes more, and throws the other one away.

You would expect that any order leaves Vlad with his favorite candy. That is not the case, because he does not necessarily have a favorite. For every pair of candies we know which one he prefers, but his choices do not have to come from a single ranking. He may choose Orange when offered Orange and Lemon, Banana when offered Orange and Banana, and Lemon when offered Lemon and Banana.

One particular candy is the one you want Vlad to end up with. Given his preference for every pair of candies, decide whether some order leaves him with that candy. If such an order exists, find the lexicographically smallest one.

Input

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

Each test case starts with a line containing the integers NN and AA, separated by a 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. If iji \ne j, then character jj of line ii differs from character ii of line jj.

Limits

  • 1T1001 \le T \le 100
  • 1N1001 \le N \le 100

Output

For each test case, output "Case #x: ", where x is the test case number starting from 11. After it, print IMPOSSIBLE if no order leaves Vlad with candy AA, and otherwise print the lexicographically smallest order that does. The order contains every candy number from 00 to N1N-1 exactly once, separated by single spaces.