#include #include #include //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") using namespace std; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; //~ while (clock()<=69*CLOCKS_PER_SEC) #define ll long long #define ld long double #define pi pair #define pd pair #define ft first #define sd second #define st first #define nd second #define mp make_pair #define pb push_back #define eb emplace_back #define FOR(i,a,b) for(int i=(a); i<=(b);i++) #define F(i,a,b) FOR(i,(a),(b)-1) #define REV(i,a,b) for(int i=(a); i>=(b);i--) #define VI vector #define VPI vector #define VPD vector #define PI 3.14159265 #define all(x) (x).begin(), (x).end() #define sz(a) (int)((a).size()) #define int long long template void _dbg(const char *sdbg, TH h){cerr< void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="< res; void dfs(int x, int p) { vis[x] = true; for (auto i : G[x]) { if (!vis[i]) { dfs(i, x); } } ruch tmp = ruch(decode(x), decode(p)); res.pb(tmp); } void solve() { char k; cin >> n >> k; res.reserve(N * N); int counter = 0; F(i, 0, n) { string s; cin >> s; F(j,0, n) { pl[i][j] = (s[j] != '.'); counter += (s[j] != '.'); } } F(i, 0, n) { F(j, 0, n) { if (pl[i][j]) { if (k == 'R' || k == 'Q') { F(l, 0, n) { if (l != j && pl[i][l]) { G[encode(pi(i, j))].eb(encode(pi(i, l))); } if (l != i && pl[l][j]) { G[encode(pi(i, j))].eb(encode(pi(l, j))); } } } if (k == 'B' || k == 'Q') { VPI V{{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}; for (auto v:V) { F(l, 1, n) { int x = i + v.ft * l, y = j + v.sd * l; if (correct(x, y) && pl[x][y]) { G[encode(pi(i, j))].eb(encode(pi(x, y))); } } } } if (k == 'N') { VPI V{{-2, 1}, {-2, -1}, {-1, 2}, {-1, -2}, {1, 2}, {1, -2}, {2, 1}, {2, -1}}; for (auto v: V) { int x = i + v.ft, y = j + v.sd; if (correct(x, y) && pl[x][y]) { G[encode(pi(i, j))].eb(encode(pi(x, y))); } } } if (k == 'K') { VPI V{{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; for (auto v: V) { int x = i + v.ft, y = j + v.sd; if (correct(x, y) && pl[x][y]) { G[encode(pi(i, j))].eb(encode(pi(x, y))); } } } } } } F(i, 0, n) { F(j, 0, n) { if (pl[i][j]) { dfs(encode(pi(i, j)), -1); break; } } if (sz(res)) break; } if (sz(res) != counter) { cout << "NO\n"; } else { cout << "YES\n"; F(j, 0, sz(res) - 1) { auto i = res[j]; cout << i.a.ft + 1 << " " << i.a.sd + 1 << " " << i.b.ft + 1 << " " << i.b.sd + 1 << "\n"; } } } int32_t main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cout<>test; F(_test, 0, test){ //cout<<"Case #"<<_test + 1<<": "; solve(); // if(_test == 1) // return 0; } return 0; } /* 3 B B.. ... ... 3 B BBB BBB BBB 3 K KKK KKK KKK */