Building a House (Large)

Find the area of the largest axis-aligned rectangle containing only grass or shrubs in a grid with fewer than 20 rock, water, or tree cells.

Easy3Brute forcePrefix sumMatrixInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You have just bought land and want to plant the largest rectangular field possible. While surveying the land you find several obstacles, so you draw a map. In each square of the map you record what the square holds: grass (G), rock (R), water (W), shrubs (S), or trees (T). The grass can be mowed and the shrubs can be dug out of the ground, but the water, rocks, and trees cannot be removed. Given the obstacles that stay, determine the area of the largest rectangular field.

A field is a rectangle whose sides are parallel to the grid of the map, and every square inside it must be grass or shrubs.

Input

The first line of input gives the number of test cases, N.

N test cases follow. For each test case there will be:

  • One line containing two space-separated integers, the length L and the width W of your land.
  • Followed by W lines, each containing L characters, where each character gives the condition of that square of land and is one of G, R, W, S, T.

Limits

  • 1 ≤ L ≤ 50
  • 1 ≤ W ≤ 50
  • N ≤ 30
  • Fewer than 20 obstacles in each test case.

Output

For each test case, output one line containing "Case #x: " followed by the area of the largest rectangle that can be cleared. x is the test case number, starting from 1. If there is no grass and no shrubs, so no field can be planted at all, output 0.