Given a matrix containing lower alphabetical characters only, we need to count number of palindromic paths in given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell.

**Input:**

The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines.

First line of each test case consist of two space separated integers R and C, denoting the number of element in a row and column respectively.

Second line of each test case consists of R*C space separated chars denoting the elements in the matrix in row major order.

**Output:**

It should be single line output, Print the respective output in the respective line.

**Constraints:**

1<=T<=20

1<=R,C<=10

**Example:
Input:**

1

3 4

a a a b b a a a a b b a

**Output:**

3

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.

SumitSingh27 | 72 |

SanketAgarwal1 | 54 |

rathiarpit29 | 52 |

ujjwalsoni1999 | 52 |

vishalkumar61 | 50 |

SumitSingh27 | 398 |

saiujwal13083 | 279 |

ujjwalsoni1999 | 277 |

NaveenKumarNakka | 275 |

_maverick7_ | 266 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.