Apocalypse Soon (Small)

On a grid of at most 5 by 5, simulate daily simultaneous attacks where each AI nation hits its strongest surviving neighbor, and choose one attack per day to survive as long as possible.

Medium7SimulationGreedyBrute forceImplementationNo attempts yetTime limit5sMemory limit512 MB

Problem

The political balance of the world has collapsed, and every nation has declared war on every other nation. The only thing left to hope for is to survive as long as possible.

Every industrial center has already been destroyed, so the only way to attack is to hurl conscripted soldiers at a neighbor. That limits each nation to attacking the nations immediately next to it. The world is an R×CR \times C grid. Rows are numbered from 1 in the far north to RR in the far south, and columns from 1 in the far west to CC in the far east. Each nation occupies one square of the grid, so it has at most 4 neighbors.

Every nation starts with a strength that everyone knows. The other nations have no concept of strategy, so each morning a nation picks the surviving neighbor with the highest strength. A tie goes to the northernmost of those nations, and then to the westernmost. It sends an army whose power equals its own current strength SS at that neighbor, and by the end of the day the target's strength drops by SS. A nation with no surviving neighbor attacks nobody. A nation whose total damage for the day is at least its own strength ends the day at strength 0 and is destroyed, and from the next day on it neither attacks nor can be attacked.

All attacks happen at the same time, and an army's power comes from the strength its nation had that morning. A nation destroyed on a given day still carries out its own attack on that day.

Your nation is in column cc, row rr, and it listens to your advice, so it does not have to follow that strategy. Each day you may pick one surviving neighbor and attack it, or do nothing at all. You cannot attack two neighbors at once, and you cannot send an army weaker than your current strength.

You survive a day if your nation's strength is above 0 when the day ends. Find the largest number of days you can survive.

Input

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

The first line of each test case contains four integers CC, RR, cc, and rr. The next RR lines contain CC integers each. The cic_i-th number on the rir_i-th of those lines is the starting strength Sci,riS_{c_i, r_i} of the nation in column cic_i and row rir_i. That value may be 0, which means the nation has already been destroyed. Your nation's starting strength is not 0.

Limits

  • 1T1001 \le T \le 100
  • 1C51 \le C \le 5
  • 1R51 \le R \le 5
  • 1cC1 \le c \le C
  • 1rR1 \le r \le R
  • 0Sci,ri100 \le S_{c_i, r_i} \le 10

Output

For each test case, print one line containing Case #A: followed by:

  • B day(s), where BB is the largest number of days you can survive.
  • forever, if you can outlast all your neighbors.

AA is the test case number, starting from 1. Write day(s) exactly that way, including when BB is 0 or 1.