Dream#499

Dream

1 second
64 megabytes
Easy

Peter fell asleep at his computer and dreamed he was in an alternate reality—a rectangular maze represented as an r \times c grid. To avoid being late for school, Peter must find a way out. His starting position is marked with an 'S', and the exit from the alternate reality is marked with an 'E'.

In one move, Peter can move to one of the four adjacent cells (left, right, up, down). If a cell contains a wall ('X'), Peter cannot enter it. Some cells contain doors with locks of one of four colors ('R', 'G', 'B', 'Y'). To pass through such a cell, Peter must have a key of the matching color. Keys are reusable and can open any number of their corresponding locks.

Peter can buy keys to reach the exit, but he wants to spend as little money as possible. Help Peter determine the minimum amount of money required to buy the set of keys that allows him to reach the exit.

Input

The first line contains the number of tests. Each test starts with two integers and (1 \leq r, c \leq 50). The second line contains integers p_i (p_i \leq 100)—the costs of purchasing the keys for 'R', 'G', 'B', and 'Y', respectively. Then lines follow, each containing characters, describing the maze. Each maze contains exactly one 'S' and one 'E'.

Output

For each test, print on a separate line the minimum amount of money required to buy the necessary set of keys to reach the exit. If it is impossible to reach the exit, print "Sleep".

Examples

Example 1

Loading
Loading