Adding up the neighbor values X39876


Statement
 

pdf   zip

thehtml

In a matrix of integers, each position may have up to four immediate neighbors: up and down by one row within the same column, and left and right by one column within the same row. Corners have only two such neighbors and the rest of the top and bottom rows have three, as do the rest of the leftmost and rightmost column.

Write a program that reads several matrices and reports whether each matrix has some position where the number in that position coincides with the sum of the neighbors.

Input

Input consists of cases. First comes a non-negative integer k indicating the number of cases. Then come the k cases, each of which starts with two positive integers n and m, the dimensions of the matrix for that case: n rows of m columns. Then come the contents of the matrix, row by row.

Output

For each of the cases, your program must print the leftmost position in the matrix containing a value equal to the sum of its neighbors; that is, the one with smallest column index. In case of a tie, report the topmost one; that is, the one with smallest row index. Row and column indexes are to start from zero. The program must print the row and column of the found position, as well as the value in it. Follow the format of the examples.

If no position in the matrix fulfills the condition, the output for that case must be the word "none".

Public test cases
  • Input

    7
    3 3
    1 2 3
    2 8 2
    3 2 1
    2 2
    1 1
    0 2
    3 4
    1   2   3 2
    0 -1 -4 0
    3   2   1 2
    3 3
    1 3 1
    3 1 -5
    1 -2 4
    3 2
    1 2
    3 4
    5 6
    4 3
    1 2 3
    2 3 4
    3 4 5
    4 5 10
    4 3
    1 2 3
    2 3 4
    3 4 5
    4 5 6
    

    Output

    row: 1 column: 1 value: 8
    row: 0 column: 0 value: 1
    row: 1 column: 3 value: 0
    row: 1 column: 0 value: 3
    none
    row: 3 column: 2 value: 10
    none
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python