Shivam is a Geek and loves playing with matrix. Given a matrix containing 0’s and 1’s. Group all the row numbers (starting index 0) which are having 1’s at same position. Shivam being lazy wants your help to do the job.

**Input:**

The first line of input consists of T test cases. Then T test cases follow. The first line of every test case consists of a integer N, denoting number of rows and columns in the matrix. Second line of every test case consists N spaced elements Ai, denoting elements of the matrix (In the form of String).

**Output:**

For each test case in a single line output for each test case, print all the space separated row indices, if not possible to print then print "-1".

**Constraints:**

1<=T<=100

1<=N<=20

**Example:
Input:**

1

4

0010 0100 0010 0000

0 1

**Explanation:**

In the above test case, first and third row have the 1's at same column,i.e., 2(starting index from 0) so group first and third row. And print the index of first row, i.e., 0 (starting index from 0).

For second row, as it is the only row with same indexing of 1's so print it's index , i.e., 1

For forth row, 1 is not present in this row so didn't print anything.

Author: saksham seth

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.