#K13756. Count Stones in a Grid

    ID: 23983 Type: Default 1000ms 256MiB

Count Stones in a Grid

Count Stones in a Grid

You are given an integer T representing the number of test cases. For each test case, you are given an integer N followed by an N × N grid. Each cell of the grid contains either 0 or 1, where 1 represents a stone. Your task is to count the total number of stones in each grid.

Important: The input is read from standard input (stdin) and the output must be written to standard output (stdout). For every test case, output the count on a new line.

In mathematical terms, if for a given grid we define the grid as an N × N matrix \(A\), you need to compute:

[ \text{result} = \sum_{i=1}^{N} \sum_{j=1}^{N} A_{ij} ]

inputFormat

The first line contains an integer T, the number of test cases. Each test case includes the following:

  • A line with an integer N — the size of the grid.
  • N subsequent lines, each containing N space-separated integers (either 0 or 1) representing the grid rows.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single integer — the total count of stones (1s) in the grid, each on a new line. The output should be written to standard output (stdout).

## sample
1
3
0 1 0
1 0 0
0 0 1
3

</p>