// 路径的权值只有0和1两种权值,可以用双端队列优化Djkstra算法,
// 权值为0的路径更新从队列前端进入,权值为1的路径更新从队列后端进入,保证队列单调上升,则每次的队头都是最短的路径
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;
typedef pair<int, int> PII;
const int N = 510;
int n, m;
char g[N][N];
int d[N][N];
bool st[N][N];
int bfs() {
memset(st, false, sizeof st);
memset(d, 0x3f, sizeof d);
deque<PII> q;
q.push_back({0, 0});
d[0][0] = 0;
int dx[] = {-1, -1, 1, 1}, dy[] = {-1, 1, -1, 1};
int ix[] = {-1, -1, 0, 0}, iy[] = {-1, 0, -1, 0};
char cs[] = "\\//\\";
while (q.size()) {
auto t = q.front();
q.pop_front();
if (st[t.first][t.second]) continue;
st[t.first][t.second] = true;
for (int i = 0; i < 4; i++) {
int x = t.first + dx[i], y = t.second + dy[i];
if (x >= 0 && x <= n && y >= 0 && y <= m) {
int w = 0;
if (g[t.first + ix[i]][t.second + iy[i]] != cs[i]) w = 1;
if (d[x][y] > d[t.first][t.second] + w) {
d[x][y] = d[t.first][t.second] + w;
if (w) q.push_back({x, y});
else q.push_front({x, y});
}
}
}
}
if (d[n][m] == 0x3f3f3f3f) return -1;
else return d[n][m];
}
int main() {
int t;
cin >> t;
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
}
int res = bfs();
if (res == -1) puts("NO SOLUTION");
else printf("%d\n", res);
}
return 0;
}