#define fi first #define se second typedef pair<int, int> pii; typedeflonglong ll; typedeflongdouble ld; //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
constint mod = 998244353; constint N = 257 + 5;
bitset<258> bot[N][N]; int n, m, k, a[N][N];
namespace Gauss { bitset<258> a[256 + 256 + 5]; int n; voidpush(const bitset<258>& x){ a[++n] = x; } boolsolve(int m){ int k = 1; for (int i = 1; i <= m; i++) { if (k > n) break; for (int j = k + 1; j <= n; j++) if (a[j][i] > 0) { swap(a[k], a[j]); break; } if (a[k][i] == 0) break; for (int j = 1; j <= n; j++) if (j != k && a[j][i]) { a[j] ^= a[k]; } ++k; } for (int i = k; i <= n; i++) if (a[i][m + 1]) returnfalse; returntrue; } }
voidMAIN(){ string s; Gauss::n = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { bot[i][j].reset(); } } cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> s; for (int j = 1; j <= m; j++) { a[i][j] = (s[j - 1] == 'B'); } } for (int i = 1; i <= m; i++) bot[1][i].set(i); for (int i = 2; i <= n; i++) { for (int j = 1; j <= m; j++) { bot[i][j] = bot[i - 1][j] ^ bot[i - 1][j - 1] ^ bot[i - 1][j + 1] ^ bot[i - 2][j]; bot[i][j][m + 1] = bot[i][j][m + 1] ^ a[i - 1][j]; } } while (k--) { int x, y; cin >> x >> y; Gauss::push(bot[x][y]); } for (int i = 1; i <= m; i++) { bitset<258> x = bot[n][i] ^ bot[n][i + 1] ^ bot[n][i - 1] ^ bot[n - 1][i]; x[m + 1] = x[m + 1] ^ a[n][i]; Gauss::push(x); } staticint Case = 0; cout << "Case #" << ++Case << ":\n"; if (Gauss::solve(m)) cout << "YES\n"; else cout << "NO\n"; }
intmain(){ #ifdef LOCAL auto start = chrono::steady_clock::now(); freopen("miku.in", "r", stdin); freopen("miku.out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); int T = 1; cin >> T; while (T--) MAIN(); #ifdef LOCAL auto end = chrono::steady_clock::now(); cout << "\nqwq: " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms\n"; #endif return0; }