#K341. Sum of Unique Integers in Grid Rows

    ID: 25234 Type: Default 1000ms 256MiB

Sum of Unique Integers in Grid Rows

Sum of Unique Integers in Grid Rows

You are given multiple grids of integers. For each grid, compute the sum of unique (distinct) integers in every row.

For a given row, let \(S\) be the set of numbers in that row. Then the answer for that row is \(\sum_{x \in S} x\). For example, for the row [1, 2, 2, 3], the set \(S\) is \(\{1, 2, 3\}\) and the sum is \(1+2+3=6\).

You need to process multiple grids. For each grid, output a single line containing the sum for each row (in order) separated by a single space.

inputFormat

The input is read from stdin and has the following format:

T
r1 c1
row1
row2
... (r1 rows for grid 1)
r2 c2
row1
row2
... (r2 rows for grid 2)
...

Where:

  • T: The number of grids.
  • For each grid, the first line contains two integers \(r\) and \(c\), representing the number of rows and columns of the grid. Each of the following \(r\) lines contains \(c\) integers separated by spaces.

outputFormat

For each grid, output one line to stdout with \(r\) integers. Each integer is the sum of unique numbers for the corresponding row in that grid. The values in each line should be separated by a single space.

## sample
2
3 3
1 2 3
4 4 4
1 2 2
3 2
2 3
3 3
1 2
6 4 3

5 3 3

</p>