#include #include #include #include #include #include #include void answer(const bool f) { std::cout << (f ? "Yes\n" : "No\n"); std::exit(EXIT_SUCCESS); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int H, W; std::cin >> H >> W; std::vector S(H); for (int i = 0; i < H; ++i) { std::cin >> S[i]; for (int j = i & 1; j < W; j += 2) S[i][j] = (S[i][j] == '.' ? '#' : '.'); } int M; std::cin >> M; std::set immutable_horizontal_edges, immutable_vertical_edges; std::generate_n(std::inserter(immutable_horizontal_edges, immutable_horizontal_edges.end()), H - 1, [i = 0]() mutable { return i++; }); std::generate_n(std::inserter(immutable_vertical_edges, immutable_vertical_edges.end()), W - 1, [j = 0]() mutable { return j++; }); std::vector mutable_horizontal_edges, mutable_vertical_edges; mutable_horizontal_edges.reserve(M); mutable_vertical_edges.reserve(M); for (int _ = 0; _ < M; ++_) { int t, n; std::cin >> t >> n; if ((t == 1 && n == H) || (t == 2 && n == W)) continue; --n; (t == 1 ? immutable_horizontal_edges : immutable_vertical_edges).erase(n); (t == 1 ? mutable_horizontal_edges : mutable_vertical_edges).emplace_back(n); } for (const auto i : immutable_horizontal_edges) for (int j = 0; j < W; ++j) if (S[i][j] != S[i + 1][j]) answer(false); for (const auto j : immutable_vertical_edges) for (int i = 0; i < H; ++i) if (S[i][j] != S[i][j + 1]) answer(false); mutable_horizontal_edges.emplace_back(H - 1); mutable_vertical_edges.emplace_back(W - 1); for (const int i : mutable_horizontal_edges) if (S[i][0] == '.') for (const int j : mutable_vertical_edges) S[i][j] = (S[i][j] == '.' ? '#' : '.'); for (const int j : mutable_vertical_edges) if (S[0][j] == '.') for (const int i : mutable_horizontal_edges) S[i][j] = (S[i][j] == '.' ? '#' : '.'); for (const char target : ".#") { bool tmp = true; for (const int i : mutable_horizontal_edges) for (const int j : mutable_vertical_edges) if (S[i][j] != target) tmp = false; if (tmp) answer(true); } answer(false); }