#include<bits/stdc++.h>
using namespace std;
const int MAX = 5e2+10;
typedef pair<int, int> PII;
int r, c, t;
char g[MAX][MAX];
int dis[MAX][MAX];
deque<PII> dq;
int da[4][2] = {-1, -1, -1, 1, 1, 1, 1, -1}; //可以走的四个方向
int db[4][2] = {-1, -1, -1, 0, 0, 0, 0, -1}; //四个方向的元件的位置
char dc[4] = {'\\', '/', '\\', '/'}; //四个方向上不需要旋转元件情况下 应该有的元件形式
int bfs(){
memset(dis, 0x3f, sizeof dis);
dq.push_front({0, 0});
dis[0][0] = 0;
/**
* 从一个点到另一个点,
* 如果不需要旋转元件,视为这条路径的权值为0
* 如果需要旋转元件,视为这条路的权值为1
* 所以从一个点到另一个点的一条路可能有不同的权值
* 也就是说,经过一个元件有两条不同方向的路(↘和↗)
* 所以经过这个元件的最短距离有可能被更小的值覆盖(dijkstra)
* 所以需要到最后出队才能确定最小的旋转次数
*
* 本题中双端队列存放时:不需要旋转插入队头,需要旋转插入队尾
**/
while(dq.size()){
PII t = dq.front();
dq.pop_front();
for(int i=0; i<4; i++){
int x = t.first, y = t.second;
int xx = x+da[i][0], yy = y+da[i][1];
if(xx<0 || xx>r || yy<0 || yy>c) continue; //格点是r+1行,c+1列
int bx = x+db[i][0], by = y+db[i][1];
int w = (g[bx][by]!=dc[i]); //权值 需要旋转,视为路径权值为1
if(dis[x][y]+w < dis[xx][yy]){
dis[xx][yy] = dis[x][y]+w;
if(w) dq.push_back({xx, yy});
else dq.push_front({xx, yy});
}
}
}
return dis[r][c];
}
int main(){
scanf("%d", &t);
while(t--){
scanf("%d%d", &r, &c);
for(int i=0; i<r; i++) scanf("%s", g[i]);
//横纵坐标和为奇数的点一定不能到达,可以画图看看哪些点能到达,哪些不能到达,找一下规律
if(r+c & 1) cout<< "NO SOLUTION"<< endl;
else cout<< bfs()<< endl;
}
return 0;
}