h, w = read_line.split.map(&.to_i) s = Array.new(h) do |i| read_line.chars.map_with_index { |ch, j| (ch == '#') ^ ((i + j) % 2 == 0) } end rs = Array.new(h, false) cs = Array.new(w, false) read_line.to_i.times do t, n = read_line.split.map(&.to_i) if t == 1 rs[n - 1] = true else cs[n - 1] = true end end (h - 2).downto(0) do |i| if s[i][-1] != s[i + 1][-1] && rs[i] 0.upto(i) do |r| w.times do |c| s[r][c] ^= true end end end end (w - 2).downto(0) do |i| if s[-1][i] != s[-1][i + 1] && cs[i] h.times do |r| 0.upto(i) do |c| s[r][c] ^= true end end end end puts h.times.all? { |i| w.times.all? { |j| s[i][j] == s[0][0] } } ? "Yes" : "No"