#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { lint H, W, M; cin >> H >> W; std::vector v(H); vin(v); cin >> M; vi t(M), n(M); lint a=0, b=0, c=0, x, y, z; set s1, s2; rep(i, M) { cin >> t[i] >> n[i]; if (t[i] == 1) s1.insert(n[i]-1); if (t[i] == 2) s2.insert(n[i]-1); } vvi w(H, vi(W)); rep(i, H) { rep(j, W) { if ((i+j)%2 == 1 && v[i][j] == '.') w[i][j] = 1; if ((i+j)%2 == 0 && v[i][j] == '#') w[i][j] = 1; } } // rep(i, H) vout(w[i]); rep(i, H-1) { rep(j, W-1) { x = w[i][j] + w[i+1][j] + w[i][j+1] + w[i+1][j+1]; if (x%2 == 1) drop("No"); } } rep(i, H-1) { rep(j, W) { if (w[i][j] != w[i+1][j]) { if (!s1.count(i)) drop("No"); } } } rep(i, H) { rep(j, W-1) { if (w[i][j] != w[i][j+1]) { if (!s2.count(j)) drop("No"); } } } std::cout << "Yes" << '\n'; }