#include <bits/stdc++.h>
using namespace std;
int row,col;
char arr[1005][1005];
bool visited[1005][1005]={false};
const int X[]={0,-1,0,1};
const int Y[]={-1,0,1,0};
int maxi=-1,maxr,maxc;
bool isinlabyrinth(int i,int j)
{
return ((i>=0 && i<row) && (j>=0 && j<col) && arr[i][j]=='.');
}
int dfs(int i,int j,int tempcount)
{
visited[i][j]=true;
if(tempcount>maxi)
{
maxi=tempcount;
maxr=i;
maxc=j;
}
for(int t=0;t<4;t++)
{
if(isinlabyrinth(i+X[t],j+Y[t]) && !visited[i+X[t]][j+Y[t]])
dfs(i+X[t],j+Y[t],tempcount+1);
}
}
int main()
{
int testcases;
cin >> testcases;
while(testcases-->0)
{
memset(visited,0,sizeof(visited));
cin >> col >> row;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
cin >> arr[i][j];
}
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(isinlabyrinth(i,j))
{
dfs(i,j,0);
break;
}
}
}
memset(visited,0,sizeof(visited));
// cout << maxi <<" " << p.first << " " << p.second << endl;
maxi=-1;
dfs(maxr,maxc,0);
cout << "Maximum rope length is " << maxi << "." << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCByb3csY29sOwpjaGFyIGFyclsxMDA1XVsxMDA1XTsKYm9vbCB2aXNpdGVkWzEwMDVdWzEwMDVdPXtmYWxzZX07CmNvbnN0IGludCBYW109ezAsLTEsMCwxfTsKY29uc3QgaW50IFlbXT17LTEsMCwxLDB9OwppbnQgbWF4aT0tMSxtYXhyLG1heGM7CmJvb2wgaXNpbmxhYnlyaW50aChpbnQgaSxpbnQgaikKewogICAgcmV0dXJuICgoaT49MCAmJiBpPHJvdykgJiYgKGo+PTAgJiYgajxjb2wpICYmIGFycltpXVtqXT09Jy4nKTsKfQppbnQgZGZzKGludCBpLGludCBqLGludCB0ZW1wY291bnQpCnsKICAgIHZpc2l0ZWRbaV1bal09dHJ1ZTsKICAgIGlmKHRlbXBjb3VudD5tYXhpKQogICAgewogICAgICAgIG1heGk9dGVtcGNvdW50OwogICAgICAgIG1heHI9aTsKICAgICAgICBtYXhjPWo7CiAgICB9CiAgICBmb3IoaW50IHQ9MDt0PDQ7dCsrKQogICAgewogICAgICAgIGlmKGlzaW5sYWJ5cmludGgoaStYW3RdLGorWVt0XSkgJiYgIXZpc2l0ZWRbaStYW3RdXVtqK1lbdF1dKQogICAgICAgICAgICBkZnMoaStYW3RdLGorWVt0XSx0ZW1wY291bnQrMSk7CiAgICB9Cn0KaW50IG1haW4oKQp7CiAgICBpbnQgdGVzdGNhc2VzOwogICAgY2luID4+IHRlc3RjYXNlczsKICAgIHdoaWxlKHRlc3RjYXNlcy0tPjApCiAgICB7CiAgICAgICAgbWVtc2V0KHZpc2l0ZWQsMCxzaXplb2YodmlzaXRlZCkpOwogICAgICAgIGNpbiA+PiBjb2wgPj4gcm93OwogICAgICAgIGZvcihpbnQgaT0wO2k8cm93O2krKykKICAgICAgICB7CiAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8Y29sO2orKykKICAgICAgICAgICAgICAgIGNpbiA+PiAgYXJyW2ldW2pdOwogICAgICAgIH0KICAgICAgICBmb3IoaW50IGk9MDtpPHJvdztpKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGo9MDtqPGNvbDtqKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGlzaW5sYWJ5cmludGgoaSxqKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBkZnMoaSxqLDApOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIG1lbXNldCh2aXNpdGVkLDAsc2l6ZW9mKHZpc2l0ZWQpKTsKICAgICAgLy8gIGNvdXQgPDwgbWF4aSA8PCIgICIgIDw8IHAuZmlyc3QgPDwgIiAgIiA8PCBwLnNlY29uZCA8PCBlbmRsOwogICAgICAgIG1heGk9LTE7CiAgICAgICAgZGZzKG1heHIsbWF4YywwKTsKICAgICAgICBjb3V0IDw8ICJNYXhpbXVtIHJvcGUgbGVuZ3RoIGlzICIgPDwgbWF4aSA8PCAiLiIgPDwgZW5kbDsKICAgIH0KfQo=