#include #include using namespace std; int main() { int loop; cin >> loop; int h, w; while (loop-- && cin >> h >> w){ //cerr << h << " " << w << endl; char table[64][64]; set letter; for (int y = 0; y != h; ++y){ for (int x = 0; x != w; ++x){ char c; cin >> c; table[x][y] = c; letter.insert(c); } } letter.erase('.'); /* for (set::iterator it = letter.begin(); it != letter.end(); ++it){ cerr << *it; } cerr << endl; */ bool safe = true; while (!letter.empty() && safe){ safe = false; for (set::iterator it = letter.begin(); it != letter.end() && !safe; ++it){ char c = *it; int min_x = 100; int min_y = 100; int max_x = -100; int max_y = -100; for (int y = 0; y != h; ++y){ for (int x = 0; x != w; ++x){ if (c == table[x][y]){ min_x = min(min_x, x); min_y = min(min_y, y); max_x = max(max_x, x); max_y = max(max_y, y); } } } safe = true; for (int y = min_y; y <= max_y && safe; ++y){ for (int x = min_x; x <= max_x && safe; ++x){ safe = (table[x][y] == c || table[x][y] == '\0'); } } //cerr << c << " " << safe << endl; if (safe){ for (int y = min_y; y <= max_y && safe; ++y){ for (int x = min_x; x <= max_x && safe; ++x){ table[x][y] = '\0'; } } letter.erase(c); break; } } } if (safe){ cout << "SAFE" << endl; } else { cout << "SUSPICIOUS" << endl; } } }