{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003eThe 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. \u003c/div\u003e\n\n\n从 S 出发,去到达每一个 A ,求最小的总路径长度,空格是空地,# 是墙,并且在走的过程中我们可以在 S 或 A 点分裂,也就是从该点可以延伸出多条路径到其他点,但是每一次只能让其中的一个继续行走。"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003eOn 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. \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003eFor every test case, output one line containing the minimal cost of a succesful search of the maze leaving no aliens alive. \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"}}]}