H,W = map(int,input().split()) S = [input() for _ in range(H)] M = int(input()) yoko = set() tate = set() for _ in range(M): t,n = map(int,input().split()) if t == 1: yoko.add(n - 1) else: tate.add(n - 1) gyo = [[0] * W for _ in range(H - 1)] retu = [[0] * (W - 1) for _ in range(H)] for i in range(H - 1): for j in range(W): if S[i][j] == S[i + 1][j]: gyo[i][j] = 0 else: gyo[i][j] = 1 for i in range(H): for j in range(W - 1): if S[i][j] == S[i][j + 1]: retu[i][j] = 0 else: retu[i][j] = 1 import sys for i in range(H - 1): zero = False one = False for j in range(W): if gyo[i][j] == 1: one = True else: zero = True if zero == one: print('No') exit() if zero: if i not in yoko: print('No') exit() for j in range(W - 1): zero = False one = False for i in range(H): if retu[i][j] == 1: one = True else: zero = True if one == zero: print('No') exit() if zero: if j not in tate: print('No') exit() print('Yes')