시간 제한메모리 제한제출정답맞힌 사람정답 비율
120 초 (추가 시간 없음) 1024 MB553240.000%

## 문제

Mr. Raven is stuck in a cave represented by a matrix of N rows and M columns, where rows are numbered from 1 to N from top to bottom, and columns are numbered from 1 to M from left to right. The cell at the i-th row and the j-th column is denoted by (i, j). Mr. Raven is currently at the cell (SR, SC), and the exit of the cave is located at the cell (TR, TC).

Some cells of the cave may contain obstacles. Mr. Raven cannot step into a cell that has an obstacle. Other cells may contain traps. The first time that Mr. Raven enters a cell with a trap, he must spend a number of energy points equal to the strength of the trap. If he has fewer energy points than needed, he cannot enter the cell. Moreover, some other cells may contain potions. The first time that Mr. Raven enters a cell with a potion, he gains energy points equal to the strength of the potion.

Mr. Raven initially has E energy points. He can move between cells that share an edge (not just a corner). On the exit cell, Mr. Raven can choose not to exit the cave and continue to explore the cave if he wants to. Can you help him find the maximum number of energy points he can have when he exits the cave, if it is possible to do so?

## 입력

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of one line with seven integers N, M, E, SR, SC, TR and TC as described above. The i-th of the next N lines describes the i-th row of the cave. Each line consists of M integers Vij; the j-th of these represents the cell in the j-th column of the i-th row. Each Vij can be one of the following

• 0: represents an empty cell.
• -100000: represents a cell with an obstacle.
• an integer between -99999 and -1 (both inclusive): represents a trap with strength -Vij.
• an integer between 1 and 99999 (both inclusive): represents a potion with strength Vij.

## 출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum energy points that Mr. Raven can have when he reaches the exit of the cave. If it is not possible for Mr. Raven to reach the exit, output -1.

## 제한

• 1 ≤ T ≤ 100.
• 1 ≤ N ≤ 100.
• 1 ≤ M ≤ 100.
• 0 ≤ E ≤ 100000.
• 1 ≤ SR ≤ N.
• 1 ≤ SC ≤ M.
• 1 ≤ TR ≤ N.
• 1 ≤ TC ≤ M.
• (SR, SC) ≠ (TR, TC).
• -100000 ≤ Vij < 100000, for all i, j.
• At most 15 cells have -100000 < Vij < 0. (There are at most 15 traps.)
• VSRSC = 0. (Mr. Raven's initial position is an empty cell.)
• VTRTC = 0. (The cell with the exit is empty.)

## Test Set 1 (19점)

• There are no cells that have Vij > 0. (There are no potions in the cave.)

## 예제 입력 1

2
4 4 100 1 1 4 4
0 0 0 0
0 0 0 0
0 0 0 -100000
0 0 -100000 0
8 8 250 7 1 1 7
-100000 -100000 -100000 -100000 -100000 -100000 0 -100000
-100000 0 -100000 0 -400 0 0 -100000
-100000 100 -300 0 -100000 -300 -100000 -100000
-100000 0 -100000 500 -100000 250 0 -100000
-100000 -200 -100000 -100000 -100000 -100000 -100 -100000
-100000 0 -100000 0 0 50 50 -100000
0 0 -100 0 -100000 50 -100000 -100000
-100000 -100000 -100000 -100000 -100000 -100000 -100000 -100000


## 예제 출력 1

Case #1: -1
Case #2: 250


## 힌트

In Sample Case #1, it is not possible for Mr. Raven to reach the exit.

In Sample Case #2, the cave is as depicted in the following image where

• A cell with a positive integer x represents a potion with strength x.
• A cell with a negative integer y represents a trap with strength -y.
• Mr. Raven's initial position is in the cell with "You are here" text.

In this case, one of the optimal ways to reach the exit with maximum energy points is to

• Go to and destroy the trap at the cell (7, 3). 150 energy points remaining.
• Collect all three potions located at positions (6, 6), (6, 7) and (7, 6). 300 energy points remaining.
• Go to an destroy the trap at the cell (5, 7). 200 energy points remaining.
• Collect the potion at the cell (4, 6). 450 energy points remaining.
• Go to and destroy the trap at the cell (5, 2). 250 energy points remaining.
• Collect the potion at the cell (3, 2). 350 energy points remaining.
• Go to and destroy the trap at the cell (3, 3). 50 energy points remaining.
• Collect the potion at the cell (4, 4). 550 energy points remaining.
• Go to and destroy the trap at the cell (3, 6) and exit with 250 energy points remaining.

Note that this case will not appear in the Small dataset.

## 채점 및 기타 정보

• 예제는 채점하지 않는다.