#include <bits/stdc++.h> using namespace std; void te() { int h, w; string s; cin >> h >> w >> s; for(int r0 = 1; r0 <= h; ++r0) for(int c0 = 1; c0 <= w; ++c0) { int row = r0, col = c0; bool ok = true; for(char dir : s) { if(dir == 'U') --row; else if(dir == 'D') ++row; else if(dir == 'L') --col; else if(dir == 'R') ++col; else assert(false); if(row == 0 || row == h + 1 || col == 0 || col == w + 1) ok = false; } if(ok) { puts("safe"); return; } } puts("unsafe"); } int main() { int T; cin >> T; while(T--) te(); }