{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of the Borg civilization. Each Borg individual is linked to the collective by a sophisticated subspace network that insures each member is given constant supervision and guidance. \n \u003cbr\u003e \n \u003cbr\u003eYour task is to help the Borg (yes, really) by developing a program which helps the Borg to estimate the minimal cost of scanning a maze for the assimilation of aliens hiding in the maze, by moving in north, west, east, and south steps. The tricky thing is that the beginning of the search is conducted by a large group of over 100 individuals. Whenever an alien is assimilated, or at the beginning of the search, the group may split in two or more groups (but their consciousness is still collective.). The cost of searching a maze is definied as the total distance covered by all the groups involved in the search together. That is, if the original group walks five steps, then splits into two groups each walking three steps, the total distance is 11\u003d5+3+3. \n \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n On the first line of input there is one integer, N \u0026lt;\u003d 50, giving the number of test cases in the input. Each test case starts with a line containg two integers x, y such that 1 \u0026lt;\u003d x,y \u0026lt;\u003d 50. After this, y lines follow, each which x characters. For each character, a space `` \u0027\u0027 stands for an open space, a hash mark ``#\u0027\u0027 stands for an obstructing wall, the capital letter ``A\u0027\u0027 stand for an alien, and the capital letter ``S\u0027\u0027 stands for the start of the search. The perimeter of the maze is always closed, i.e., there is no way to get out from the coordinate of the ``S\u0027\u0027. At most 100 aliens are present in the maze, and everyone is reachable. \n \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n For every test case, output one line containing the minimal cost of a succesful search of the maze leaving no aliens alive. \n \u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e2\n6 5\n##### \n#A#A##\n# # A#\n#S ##\n##### \n7 7\n##### \n#AAA###\n# A#\n# S ###\n# #\n#AAA###\n##### \n\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e8\n11\u003c/pre\u003e"}},{"title":"提示","value":{"format":"HTML","content":"友情提示:如果题面看不懂可以尝试理解下样例。还有就是这个题的输入n和m的后面可能会有多余的空格,自己看着处理喽。"}}]}