#include<stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
char radka[1024][1024];
char buf[1024];
int delky[1024][1024];
int r,c,n,m,i,j,k,l;
int hledej(int x,int y) {
 int a,b,c,d,l;
 radka[x][y]=-1;
 if ((radka[x-1][y]=='.')&&(!delky[x-1][y])) a=hledej(x-1,y); else a=0;
 if ((radka[x+1][y]=='.')&&(!delky[x+1][y])) b=hledej(x+1,y); else b=0;
 if ((radka[x][y-1]=='.')&&(!delky[x][y-1])) c=hledej(x,y-1); else c=0;
 if ((radka[x][y+1]=='.')&&(!delky[x][y+1])) d=hledej(x,y+1); else d=0;
 l=a+b;
 if (l<a+c) l=a+c;
 if (l<a+d) l=a+d;
 if (l<b+c) l=b+c;
 if (l<b+d) l=b+d;
 if (l<c+d) l=c+d;
 if (m<l) m=l;
 return delky[x][y]=max(max(a,b),max(c,d))+1;
 }

int main() {
 gets(buf);
 sscanf(buf,"%d",&n);
 while (n--) {
  gets(buf);
  sscanf(buf,"%d %d",&c,&r);
  m=0;
  for (i=0; i<r; i++) gets(radka[i]);
  for (i=0; i<r; i++) 
   for (j=0; j<c; j++)
    if ((!delky[i][j])&&(radka[i][j]=='.'))
     hledej(i,j);
  for (i=0; i<r; i++)
   for (j=0; j<c; j++)
    delky[i][j]=0;
  printf("Maximum rope length is %d.\n",m);
  }
 return 0;
 }
