spoj#TILING. Rectangle Tiling
Rectangle Tiling
We say that a 2-dimensional, rectangular word w of size n×m (imagine it as a board with letter written in the squares) can be tiled with a rectangular pattern p if there are such occurrences of p in w (but not necessarily all of them) that no two of them overlap and each symbol (square) of w is covered by one of them. Given such word w, find a rectangular pattern p of smallest size (area) which the word w can be tiled with.
Input
The first line of input contains a number t (1≤t≤100) that indicates the number of test cases to follow. Each test case begins with a line consisting of two positive integers n and m (1≤n,m≤1000) indicating dimensions of the board. n lines follow, each of them containing m small letters of the English alphabet (a,b,...,z).
Output
For each test case output the smallest possible area of a pattern p that can be used to tile the given board.
Example
Input: 3 4 3 aaa aaa aaa aaa 4 4 abab cdcd abab cdcd 3 4 aaaa aaaa aaabOutput: 1 4 12