#include <cstring>
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
const int N = 510, M = N * N;
int n, m;
char g[N][N];
int dist[N][N];
bool st[N][N];
int bfs() {
int hh = 0, tt = 0;
memset(st, false, sizeof st);
memset(dist, 0x3f, sizeof dist);
int dx[4] = {-1, -1, 1, 1}, dy[4] = {-1, 1, 1, -1};
int ix[4] = {-1, -1, 0, 0}, iy[4] = {-1, 0, 0, -1};
char cs[5] = "\\/\\/";
deque<pair<int, int>> q;
q.push_back({0, 0});
dist[0][0] = 0;
while (q.size()) {
auto t = q.front();
q.pop_front();
int x = t.first, y = t.second;
if (st[x][y]) continue;
if (x == n && y == m) return dist[x][y];
st[x][y] = true;
for (int i = 0; i < 4; i++) {
int a = x + dx[i], b = y + dy[i];
//边长是n, 但会有n+1个点,所以是 a>n
if (a < 0 || a > n || b < 0 || b > m) continue;
int ga = x + ix[i], gb = y + iy[i];
int w = (g[ga][gb] != cs[i]);
int d = dist[x][y] + (g[ga][gb] != cs[i]);
if (d <= dist[a][b]) {
dist[a][b] = d;
if (w == 0) q.push_front({a, b});
else q.push_back({a, b});
}
}
}
return -1;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", g[i]);
if (n + m & 1) puts("NO SOLUTION");
else cout << bfs() << endl;
}
}