import Control.Monad import Data.Char import Data.Graph import Data.Ix import Data.List main = getLine >>= flip replicateM_ f . read where f = do [h,_] <- liftM (map read . words) getLine putStrLn . solve =<< replicateM h getLine solve bd = if ans then "SAFE" else "SUSPICIOUS" where ans = not $ or [(os!!b,os!!a)`elem`hed | a <- [0..n-1], b <- [a+1..n-1]] n = length os os = topSort $ buildG (ord '.',ord 'Z') hed hed = nub $ eds ++ [(ord '.',ord c) | c <- ['A'..'Z']] eds = [(ord c,ord d) | (c,lu,rd) <- rs, (x,y) <- range (lu,rd), let d = bd!!y!!x, d/=c] rs = flip map ps $ \ls@((c,_):_) -> let (xs,ys)=(map (fst.snd) ls,map (snd.snd) ls) in (c,(minimum xs,minimum ys),(maximum xs,maximum ys)) ps = groupBy (\a b -> fst a == fst b) $ sort [(c,(x,y)) | (l,y)<- zip bd [0..], (c,x) <- zip l [0..]]