#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<int, int>PII;
const int N = 510, M = N * N;
int dx[4] = { -1,-1,1,1 };
int dy[4] = { -1,1,1,-1 };
int ix[4] = { -1,-1,0,0 };
int iy[4] = { -1,0,0,-1 };
char cs[] = "\\/\\/";
int n, m;
char g[N][N];
int dist[N][N];
bool st[N][N];
int bfs()
{
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
dist[0][0] = 0;
deque<PII>q;
q.push_back({ 0,0 });
while (q.size())
{
auto t = q.front();
q.pop_front();
if (st[t.x][t.y])continue;
st[t.x][t.y] = true;
for (int i = 0; i < 4; i++)
{
int a = t.x + dx[i], b = t.y + dy[i];
if (a<0 || a>n || b<0 || b>m)continue;
int ca = t.x + ix[i], cb = t.y + iy[i];
int d = dist[t.x][t.y] + (g[ca][cb] != cs[i]);
if (d < dist[a][b])
{
dist[a][b] = d;
if (g[ca][cb] != cs[i])q.push_back({ a,b });
else q.push_front({ a,b });
}
}
}
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 == 0x3f3f3f3f)puts("NO SOLUTION");
else printf("%d\n", t);
}
return 0;
}