sonya birthday recently she present matrix size ntime m consist lowercase latin letter we assume row number integer 1 n column number 1 m leave right Lets submatrix i_1 j_1 i_2 j_2 1leq i_1leq i_2leq n 1leq j_1leq j_2leq m element a_ij matrix i_1leq ileq i_2 j_1leq jleq j_2 Sonya state submatrix beautiful independently reorder character row column row column submatrix form palidrom Lets recall string call palindrome read leave right right leave for example string abacaba bcaacb palindrome string abca acbba ab notHelp Sonya find number beautiful submatrixe Submatrixes different element belong submatrix