Dragon Maze (Large)

In a grid with blocked cells, walk from the entrance to the exit in the fewest moves and collect the most power among such walks.

Medium5BFSDynamic programmingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You are the prince of the Dragon Kingdom, and your kingdom is running out of power. To save your people you have to find new power. An old legend says the power sits in a place called the Dragon Maze. The Dragon Maze appears anywhere without notice and disappears just as suddenly. You know where it is right now, so you have to collect power before it vanishes.

The Dragon Maze is a rectangle 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). Each cell is either a dangerous cell you can never leave once you enter it, or a safe cell holding some amount of power. Entering a safe cell collects its power automatically, and the power of a cell is collected only once. One move takes you to a cell that shares an edge with your current cell, up, down, left, or right.

You know where the entrance cell and the exit cell are. They are different cells and both are safe. To get out before the maze disappears you have to walk from the entrance to the exit in as few moves as possible. When several such walks exist, take the one that collects the largest total power. The power in the entrance cell counts too.

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 contain MM numbers each, separated by spaces, describing the cells of the maze from top to bottom. Each number is either 1-1 for a dangerous cell, or a positive integer giving the amount of power in that safe cell.

Limits

  • The power in one cell does not exceed 1000010000.
  • 1T301 \le T \le 30
  • 0enx,exx<N0 \le en_x, ex_x < N
  • 0eny,exy<M0 \le en_y, ex_y < M
  • 1N,M1001 \le N, M \le 100

Output

For each test case print one line in the form Case #x: y, where xx is the test case number starting from 11. If you can walk from the entrance to the exit, yy is the maximum total power you can collect while taking the fewest possible moves. If you cannot, yy is the string Mission Impossible.. The judge compares the output character by character, so mission impossible. or Mission Impossible without the trailing period is wrong.