#K33712. Product of Non-Zero Elements

    ID: 25149 Type: Default 1000ms 256MiB

Product of Non-Zero Elements

Product of Non-Zero Elements

Given T test cases, each consisting of a line containing space-separated integers, compute the product of all non-zero elements of the list. If every element in the list is zero or the list is empty, return 0.

Mathematically, for a test case with numbers \(a_1, a_2, \dots, a_n\), compute:

\(\prod_{i:\, a_i\neq 0} a_i\), with the convention that if no \(a_i\) is non-zero, the result is 0.

All input is provided via standard input, and the results should be printed to standard output.

inputFormat

The first line contains a single integer \(T\), the number of test cases. Each of the next \(T\) lines contains a sequence of space-separated integers.

outputFormat

For each test case, output a single line containing the product of all non-zero integers. If there are no non-zero integers, output 0.

## sample
3
1 2 3 4 5
0 6 0 7
0 0 0 0
120

42 0

</p>