Dragon Maze (Small)

Find the fewest-step walk from the entrance to the exit of a cell grid and report the most power gathered on such a route.

Medium5BFSShortest pathDynamic programmingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You are the prince of the dragon kingdom, and the kingdom is about to run out of power. You have to find power to save the kingdom and its people. An old legend says that the power sits in a place called the Dragon Maze. The Dragon Maze appears without notice and disappears without warning. You know where it is right now, so you have to collect power before it is gone.

The Dragon Maze is a rectangular grid of N×MN \times M cells. The top left cell is (0,0)(0, 0) and the bottom right cell is (N1,M1)(N-1, M-1). Every cell is either a dangerous cell that you can never leave once you enter it, or a safe cell that holds a certain amount of power. The power in a safe cell is collected the moment you enter it, and each cell gives its power only once. In one step you move to a cell that is adjacent up, down, left, or right.

You already know the entrance cell and the exit cell. They are different cells and both of them are safe. To get out before the maze disappears, you have to walk from the entrance to the exit in as few steps as possible. When several paths use the fewest steps, take the one that collects the most power. The power in the entrance cell is collected as well.

For each test case, report the total power collected that way.

Input

The first line contains the number of test cases, TT. TT test cases follow.

The first line of each test case contains two integers NN and MM, the size of the maze. The second line contains four integers enxen_x, enyen_y, exxex_x, exyex_y: the entrance cell is (enx,eny)(en_x, en_y) and the exit cell is (exx,exy)(ex_x, ex_y). The next NN lines describe the rows of the maze from top to bottom, each with MM numbers separated by spaces. Each number is either 1-1 for a dangerous cell, or a positive integer for the power held by a safe cell.

Limits

  • 1T301 \le T \le 30
  • 1N,M101 \le N, M \le 10
  • 0enx,exx<N0 \le en_x, ex_x < N
  • 0eny,exy<M0 \le en_y, ex_y < M
  • The power in a cell does not exceed 1000010\,000.
  • The entrance cell and the exit cell are different, and both are safe.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1. If you can walk from the entrance to the exit, yy is the maximum power you can collect while taking the fewest possible steps. Otherwise yy is Mission Impossible.

The judge compares the output exactly. Mission Impossible without the trailing period, or mission impossible. in lower case, is judged wrong.