#include"stdio.h"
#include"string.h"
#include"deque"
#include"algorithm"
using namespace std;
#define INF 1001010
typedef pair<int,int> PII;
const int dir1[4][2] = {{1,1},{-1,-1},{-1,1},{1,-1}};
const int dir2[4][2] = {{1,1},{0,0},{0,1},{1,0}};
int T,R,C;
char Graph[510][510];
int vis[510][510];
int dp[510][510];
int minx;
int check(int a,int b)
{
if(a >= 0 && a <= R && b >= 0 && b <= C)
return 1;
return 0;
}
void bfs()
{
deque<PII> Q;
Q.push_front({0,0});
vis[0][0] = 1;
dp[0][0] = 0;
while(!Q.empty())
{
PII T = Q.front(); Q.pop_front();
int x = T.first,y = T.second;
for(int i = 0; i < 4; i ++)
{
int x1 = x + dir1[i][0],y1 = y + dir1[i][1];
int a = x + dir2[i][0],b = y + dir2[i][1];
if(check(x1,y1) == 0) continue;
int time = (Graph[a][b] != (i <= 1 ? '\\' : '/'));
if( dp[x1][y1] <= dp[x][y] + time ) continue;
// vis[x1][y1] = 1;
dp[x1][y1] = dp[x][y] + time;
//printf("a = %d b = %d x = %d y = %d x1 = %d y1 = %d dp[x][y] = %d time = %d\n",a,b,x,y,x1,y1,dp[x][y],time);
if(time == 0)
Q.push_front({x1,y1});
else
Q.push_back({x1,y1});
}
}
return ;
}
int main()
{
scanf("%d",&T);
while(T --)
{
scanf("%d%d",&R,&C);
memset(vis,0,sizeof(vis));
for(int i = 0; i <= R;i ++)
for(int j = 0; j <= C; j ++)
dp[i][j] = INF;
for(int i = 1; i <= R; i ++)
scanf("%s",Graph[i] + 1);
bfs();
if(dp[R][C] == INF)
printf("NO SOLUTION\n");
else
printf("%d\n",dp[R][C]);
}
}