Given a 2-D integer array A of order NXN, consisting of only zeroes and ones, find the row or column whose all elements form a palindrome. If more than one palindrome is found, the palindromes found in rows will have priority over the ones found in columns and within rows and columns, the one with lesser index gets the highest priority. Print the palindrome with the highest priority along with it's index and indication of it being a row or column.

**Input:**

First line of input is an integer T, denoting the number of test cases. Each test case has two lines of input. First line consists of an integer N, denoting order of matrix A. Second line consists of NXN elements of the matrix A.

**Output:**

For each test case, there is a single line of output comprising of two parts. First, the index of either row or column(0 based indexing) , followed by either of the two characters 'R' or 'C', representing whether the palindrome was found in a row or column. All the characters printed as output should be space separated. If no palindrome is found, print -1 as the ouput in new line.

**Constraints:**

1<=T<=100

1<=N<=10

A[i][j]=0 or 1, where i and j denote row and column indices of the matrix respectively.

**Example:**

**Input:**

4

3

1 0 0 0 1 0 1 1 0

2

1 0 1 0

4

0 0 1 0 1 1 0 1 0 1 1 1 1 1 0 1

3

1 0 0 0 1 1 0 1 0

**Output:**

1 R

0 C

-1

2 C

**Explanation:**

In the first test case, 0-1-0 is a palindrome occuring in a row having index 1.

In the second test case, 1-1 occurs before 0-0 in the 0th column. And there is no palindrome in the two rows.

There is no palindrome in either any row or any column. Hence, -1 is printed.

In the third test case, 0-1-0 occurs in the second column.

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.

murli01 | 343 |

decoder_101 | 274 |

john_wick | 204 |

singhalsaurav1997 | 196 |

Sulagna | 189 |

john_wick | 725 |

PiyushPandey4 | 717 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

decoder_101 | 512 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.