Medium Accuracy: 37.48% Submissions: 315 Points: 4

Aakriti, Avantika and Mehak are playing Hopscotch (Stapu). The arena is in the form of 2d Array with little modification as shown below:

So, in this game the person who is playing need to collect stones present on the tiles that are adjacent to the tile on which the player stands. Mehak is playing and if Avantika asks her to collect stones then she will move only one step in any direction to collect all the stones from the tiles that are touching the edge with the tile on which she is standing. But if Aakriti ask her, she will move two steps in any direction and then collect stones. Help Mehak to count the total number of stones she collected.

Input: The first line of input contains integer T denoting the number of test cases. Each test case has subsequent two lines of input. The first line contains 2 integer inputs i.e N and M the size of the matrix W.Next line contains the NX M space separated elements of the matrix W i.e. stones. Next line takes a boolean and 2 integers input i.e. a , i, j. If a is 0 means Avantika asks her to collect and 1 means Aakriti asks herand (i,j)denotes the index of tile where she is standing.

Output:
For each test case, output is the total number of stones she will collect.

Explanation:
1. 0 1 1 means Avantika asks her to collect so she will move one step and collect stones from the tiles that have common edge. Here (0,1), (1,0), (1,2), (2,1), (2,2), (2,0) have common edge with the tile (1,1). So adding all 9+6+5+8+1+2=31.
2. 1 1 1 means Aakriti asks her to collect so she will move two steps. Here (0,0) and (0,2) are the tiles , hence adding them 5+7 =12.