#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using modint = atcoder::static_modint<998244353>; int main(){ int H,W; cin >> H >> W; vector S(H); rep(y,H) cin >> S[y]; auto inverse = [](char c) -> char { return '#' ^ '.' ^ c; }; if(S[0][0] == '#') rep(y,H) rep(x,W) S[y][x] = inverse(S[y][x]); rep(y,H) rep(x,W) if((y+x)&1) S[y][x] = inverse(S[y][x]); vector> A(H, vector (W)); rep(y,H-1) rep(x,W-1) A[y][x] = (S[y][x]^S[y+1][x]^S[y][x+1]^S[y+1][x+1]) ? 1 : 0; rep(y,H-1) A[y][W-1] = (S[y][W-1]^S[y+1][W-1]) ? 1 : 0; rep(x,W-1) A[H-1][x] = (S[H-1][x]^S[H-1][x+1]) ? 1 : 0; int M; cin >> M; rep(i,M){ int t, n; cin >> t >> n; if(t == 1) A[n-1][W-1] = 0; if(t == 2) A[H-1][n-1] = 0; } bool ans = true; rep(y,H) rep(x,W) if(A[y][x]) ans = false; cout << (ans ? "Yes\n" : "No\n"); return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;