City

A group of urban planners are tasked with design of a new city. The new city is rectangleshape city. The city will be divided into N rows and M columns of same-size square blocks. There are also several streets lying between these blocks. The table below represents the top-view map of one particular city having 4 rows by 6 columns of same-size square blocks. Each block is indicated by a star (‘*’). The black borders between each block represent streets. In order to go from one block to adjacent block, one has to cross the street using a crosswalk. Each crosswalk must connect a pair of horizontally or vertically adjacent blocks. Moreover, there may be more than one crosswalk between each pair of blocks. We say that a crosswalk A belongs to a block B, if and only if, the crosswalk A connects the block B with any horizontally or vertically adjacent block of the block B. We know the number of crosswalks that belongs to each block except only one block. Your task is to find the number of crosswalks of that block. Input The first line contains a single integer T indicate the number of test cases (1 ≤ T ≤ 10). Then T test cases follow.

  1. The first line of each test case contains two integers: N and M. The number of rows of blocks is N and the number of columns of blocks is M (3 ≤ N,M ≤ 500).
  2. Next N lines contain the number of crosswalks that belongs to each block. Each line describes the crosswalks of a row of the grid, starting from the top row to the bottom row. In each line, there are M integers that describes the number of crosswalks belongs to each grid in that row, starting from the leftmost block to the rightmost block. The number of crosswalks for each block is a non-negative integer not exceeding 1,000. There will be exactly one block that is represented by ‘-1’. That block is the block that we don’t know the number of crosswalks. Output For each test case, print one line contains the number of crosswalks of the block that the number of crosswalks has not been counted.

2/2 Sample Input 1 33 223 1 -1 3 110 Sample Output 1