City Game

Time limit1sMemory limit128 MB

Summary
Given several grid maps of free and reserved cells, find the largest all-free rectangle in each grid and print its area times three.
Level

Medium6 of 10

Topics
Stack, Dynamic programming, Matrix
Solved
No attempts yet

Problem

Bob is a strategy-game programming specialist. In his new city-building game, a city is made up of areas that contain streets, trees, factories, and buildings, together with some unoccupied space. The goal is to earn as much rent as possible from the free space by erecting buildings. Every building must be rectangular, and you want to make it as large as possible. You may not build over any occupied unit — existing buildings, trees, factories, or streets must stay intact.

Each area is divided into a grid of equal square units. The rent earned for each unit covered by a building is 3$. The whole city is divided into KK areas; each area has its own length MM and width NN. Occupied units are marked R and free units are marked F.

For each area, help Bob find the largest rectangular building he can erect and report the rent it earns.

Input

The first line contains an integer KK, the number of areas. Each area is described as follows. The first line contains two integers — the length MM (M≤1000M \le 1000) and the width NN (N≤1000N \le 1000) — separated by a space. The next MM lines each contain NN symbols, separated by single spaces:

  • R — a reserved (occupied) unit
  • F — a free unit

A separating line follows each area description.

Output

For each area, print on its own line the profit from erecting the largest possible rectangular building in that area — that is, the building's area in units multiplied by 33.

Examples1

  1. Example 1

    Input
    2
    5 6
    R F F F F F
    F F F F F F
    R R R F F F
    F F F F F F
    F F F F F F
    
    5 5
    R R R R R
    R R R R R
    R R R R R
    R R R R R
    R R R R R
    
    Expected output
    45
    0