{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eIt is written in the Book of The Lady: After the Creation, the cruel god Moloch rebelled against the authority of Marduk the Creator.Moloch stole from Marduk the most powerful of all the artifacts of the gods, the Amulet of Yendor, and he hid it in the dark cavities of Gehennom, the Under World, where he now lurks, and bides his time.\u003cbr\u003e\u003cbr\u003eYour goddess The Lady seeks to possess the Amulet, and with it to gain deserved ascendance over the other gods.\u003cbr\u003e\u003cbr\u003eYou, a newly trained Rambler, have been heralded from birth as the instrument of The Lady. You are destined to recover the Amulet for your deity, or die in the attempt. Your hour of destiny has come. For the sake of us all: Go bravely with The Lady!\u003cbr\u003e\u003cbr\u003eIf you have ever played the computer game NETHACK, you must be familiar with the quotes above. If you have never heard of it, do not worry. You will learn it (and love it) soon.\u003cbr\u003e\u003cbr\u003eIn this problem, you, the adventurer, are in a dangerous dungeon. You are informed that the dungeon is going to collapse. You must find the exit stairs within given time. However, you do not want to leave the dungeon empty handed. There are lots of rare jewels in the dungeon. Try collecting some of them before you leave. Some of the jewels are cheaper and some are more expensive. So you will try your best to maximize your collection, more importantly, leave the dungeon in time.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Standard input will contain multiple test cases. The first line of the input is a single integer T (1 \u0026lt;\u003d T \u0026lt;\u003d 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.\u003cbr\u003e\u003cbr\u003eThe first line of each test case contains four integers W (1 \u0026lt;\u003d W \u0026lt;\u003d 50), H (1 \u0026lt;\u003d H \u0026lt;\u003d 50), L (1 \u0026lt;\u003d L \u0026lt;\u003d 1,000,000) and M (1 \u0026lt;\u003d M \u0026lt;\u003d 10). The dungeon is a rectangle area W block wide and H block high. L is the time limit, by which you need to reach the exit. You can move to one of the adjacent blocks up, down, left and right in each time unit, as long as the target block is inside the dungeon and is not a wall. Time starts at 1 when the game begins. M is the number of jewels in the dungeon. Jewels will be collected once the adventurer is in that block. This does not cost extra time.\u003cbr\u003e\u003cbr\u003eThe next line contains M integers,which are the values of the jewels.\u003cbr\u003e\u003cbr\u003eThe next H lines will contain W characters each. They represent the dungeon map in the following notation:\u003cbr\u003e\u0026gt; [*] marks a wall, into which you can not move;\u003cbr\u003e\u0026gt; [.] marks an empty space, into which you can move;\u003cbr\u003e\u0026gt; [@] marks the initial position of the adventurer;\u003cbr\u003e\u0026gt; [\u0026lt;] marks the exit stairs;\u003cbr\u003e\u0026gt; [A] - [J] marks the jewels.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Results should be directed to standard output. Start each case with \"Case #:\" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.\u003cbr\u003e\u003cbr\u003eIf the adventurer can make it to the exit stairs in the time limit, print the sentence \"The best score is S.\", where S is the maximum value of the jewels he can collect along the way; otherwise print the word \"Impossible\" on a single line.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n\r\n4 4 2 2\r\n100 200\r\n****\r\n*@A*\r\n*B\u0026lt;*\r\n****\r\n\r\n4 4 1 2\r\n100 200\r\n****\r\n*@A*\r\n*B\u0026lt;*\r\n****\r\n\r\n12 5 13 2\r\n100 200\r\n************\r\n*B.........*\r\n*.********.*\r\n*@...A....\u0026lt;*\r\n************\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\r\nThe best score is 200.\r\n\r\nCase 2:\r\nImpossible\r\n\r\nCase 3:\r\nThe best score is 300.\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}