SP10242 ACPC11D - Dice on a Board

Description

You and your friends like to play chess and backgammon every day. But now you are bored of these games, and you would like to play a new game. So you decided to make your own game, which will be played using a backgammon die (singular of dice) on a board similar to the chess board, and it will be a single player game. [![](http://img266.imageshack.us/img266/6522/imau.png)](http://imageshack.us/photo/my-images/266/imau.png/ "ImageShack - Image And Video Hosting")

Input Format

Your program will be tested on one or more test cases. The first line of the input will be a single integer T , the number of test cases (1 Each test case is specified in N + 2 lines. The first line contains two integers N and M (1 1\. '.' means an empty cell. 2\. 'S' means the starting cell (which will appear exactly once in the board). 3\. 'T' means the target cell (which will appear exactly once in the board). 4\. A digit from '0' to '9' means the value written in this cell.

Output Format

For each test case, output, on a single line, one of these values: 1\. "Impossible" if you can not reach the target cell from the starting cell. 2\. "Infinity" if there is no limit for your final score, and you can increase it with no limit. 3\. Otherwise, output the maximum score which you can get.