Language: C++

#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int work[8],count;
};

int H,W,word_num,loc[128];
char map[50][51],word_table[8];
bool isOK;


void func(){

	for(int i = 0; i < 128; i++)loc[i] = -1;
	word_num = 0;

	scanf("%d %d",&H,&W);
	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W; k++){
			if(map[i][k] != '.'){
				if(loc[map[i][k]-'0'] == -1){ //????????´?????´???
					loc[map[i][k]-'0'] = word_num;
					word_table[word_num] = map[i][k];
					word_num++;
				}
			}
		}
	}

	bool FLG = true;
	int most_left,most_right,most_top,most_bottom;
	char ch;

	for(int i = 0; i < word_num; i++){
		ch = word_table[i];

		most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(map[row][col] == ch){
					most_left = min(most_left,col);
					most_right = max(most_right,col);
					most_top = min(most_top,row);
					most_bottom = max(most_bottom,row);
				}
			}
		}

		for(int row = most_top; row <= most_bottom; row++){
			for(int col = most_left; col <= most_right; col++){
				if(map[row][col] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)break;
		}
	}

	if(!FLG){
		printf("SUSPICIOUS\n");
		return;
	}

	isOK = false;

	queue<Info> Q;

	Info first;
	first.count = 0;
	for(int i = 0; i < word_num; i++)first.work[i] = -1;
	Q.push(first);

	while(!Q.empty()){

		if(Q.front().count == word_num){

			FLG = true;

			for(int i = 0; i < word_num; i++){
				ch = word_table[i];
				rank = Q.front().work[i];

				most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

				for(int row = 0; row < H; row++){
					for(int col = 0; col < W; col++){
						if(map[row][col] == ch){
							most_left = min(most_left,col);
							most_right = max(most_right,col);
							most_top = min(most_top,row);
							most_bottom = max(most_bottom,row);
						}
					}
				}

				for(int row = most_top; row <= most_bottom; row++){
					for(int col = most_left; col <= most_right; col++){
						if(map[row][col] != ch){
							if(rank > Q.front().work[loc[map[row][col]-'0']]){
								FLG = false;
								break;
							}
						}
					}
					if(!FLG)break;
				}
			}

			if(FLG){
				isOK = true;
				break;
			}
		}

		for(int i = 0; i < word_num; i++){
			if(Q.front().work[i] == -1){
				Info next;
				for(int k = 0; k < 8; k++)next.work[k] = Q.front().work[k];
				next.work[i] = Q.front().count;
				next.count = Q.front().count+1;

				Q.push(next);
			}
		}

		Q.pop();
	}

	if(isOK){
		printf("SAFE\n");
	}else{
		printf("SUSPICIOUS\n");
	}
}


int main(){

	int num;
	scanf("%d",&num);

	for(int i = 0; i < num; i++)func();

	return 0;
}

Compiler output:
a.cc: In function 'void func()':
a.cc:98:38: error: expected unqualified-id before '=' token
   98 |                                 rank = Q.front().work[i];
      |                                      ^
a.cc:116:65: error: expected unqualified-id before '>' token
  116 |                                                         if(rank > Q.front().work[loc[map[row][col]-'0']]){
      |                                                                 ^