//双端队列优化
//这道题就相当于dijkstra了,边的权值为0||1
//由于0的特殊性,我们可以使用双端队列来优化堆
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N=510;
typedef pair<int,int>PII;
char g[N][N];
int dist[N][N];
int n,m;
int bfs()
{
memset(dist,0x3f,sizeof dist);
deque<PII> dq;
dq.push_front({0,0});
dist[0][0]=0;
int dx[4]={-1,-1,1,1},dy[4]={-1,1,1,-1};
int di[4]={-1,-1,0,0},dj[4]={-1,0,0,-1};
char ch[]={"\\/\\/"};
while(dq.size())
{
auto op=dq.front();
dq.pop_front();
int x=op.first,y=op.second;
for(int i=0;i<4;i++)
{
int wx=x+dx[i],wy=y+dy[i];
if(wx>=0&&wx<=n&&wy>=0&&wy<=m)
{
int w=0;
int kx=x+di[i],ky=y+dj[i];
if(g[kx][ky]!=ch[i])w=1;
if(dist[wx][wy]>dist[x][y]+w)
{
dist[wx][wy]=dist[x][y]+w;
if(w)dq.push_back({wx,wy});
else dq.push_front({wx,wy});
}
}
}
}
if(dist[n][m]==0x3f3f3f3f)return -1;
return dist[n][m];
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>m;
for(int i=0;i<n;i++)cin>>g[i];
int t=bfs();
if(t==-1)cout<<"NO SOLUTION"<<endl;
else cout<<t<<endl;
}
return 0;
}