Lunch

No attempts yetTime limit1sMemory limit128 MB

Problem

There are plenty of tasty lunch options on campus. Before eating, you and your friends like to gather at a single meeting point and then walk together to a restaurant. You want to choose the meeting point and the restaurant so that the total walking distance for the whole group is as small as possible.

You are given a map of the campus. Some squares are marked as meeting points and others as restaurants, and you are told the square from which each person (you and each friend) starts. Once a meeting point and a restaurant are chosen, every person walks from their own starting square to the meeting point, then on to the restaurant, and finally back to their own starting square.

Among all valid choices, pick the pair of one meeting point and one restaurant that minimizes the total distance walked by everyone combined. You may move only up, down, left, or right between adjacent squares, never diagonally.

Input

The first line contains an integer $K \ge 1$, the number of data sets. Each data set has the following form.

The first line of a data set contains two integers $h$ and $w$, the height and width of the map ($1 \le h, w \le 30$). The next $h$ lines each contain $w$ characters, where each character is one of:

  • X — an inaccessible square (a building, a fence, and so on).
  • . — an accessible square.
  • R — a restaurant. You may not walk through a restaurant, but you may step into it from, or out of it to, any adjacent accessible square.
  • M — a meeting point. You may walk through meeting points.
  • S — a starting square for you or one of your friends. You may walk through starting squares.

You may move only up, down, left, or right, never diagonally.

Output

For each data set, first print a line Data Set x:, where $x$ is the data set number (starting from 1). On the next line, print the minimum possible total distance walked by you and all of your friends, using the best pair of one meeting point and one restaurant. You do not need to print the route.

If there is no meeting point, or no restaurant, that is reachable from every starting square, print Impossible instead of a number.