//1506的加强版,也算是搞清一种输入字符二维数组的方式了= =
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int l[1005],r[1005],a[1005][1005];
int main()
{
int k;
scanf("%d",&k);
char str[10];
while(k--)
{
int m,n;
scanf("%d%d",&m,&n);
int i,j;
for(j=1;j<=n;j++) a[0][j]=0;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%s",str);
//cout<<str[0];
if(str[0]=='F')
a[i][j]=a[i-1][j]+1;
else
a[i][j]=0;
}
}
int ans=0;
for(i=1;i<=m;i++)
{
int t;
for(j=1;j<=n;j++) l[j]=r[j]=1;
for(j=2;j<=n;j++)
{
t=j-1;
while(a[i][t]>=a[i][j]&&t>=1)
{
l[j]+=l[t];
t=t-l[t];
}
}
for(j=n-1;j>=1;j--)
{
t=j+1;
while(a[i][t]>=a[i][j]&&t<=n)
{
r[j]+=r[t];
t=t+r[t];
}
}
for(j=1;j<=n;j++)
{
int res=a[i][j]*(l[j]+r[j]-1);
//cout<<res;
if(ans<res) ans=res;
}
}
printf("%d\n",ans*3);
}
return 0;
}