import copy H,W = map(int, input().split()) MAP = [list(input()) for _ in range(H)] M = int(input()) TN = [list(map(int, input().split())) for _ in range(M)] for i in range(H): for j in range(W): if (i+j)%2==1: if MAP[i][j]=='.': MAP[i][j]='#' else: MAP[i][j]='.' for i in range(2 ** M): TNN = [] for j in range(M): if ((i >> j) & 1): TNN.append(TN[j]) CMAP = copy.deepcopy(MAP) for t,n in TNN: if t==1: for i in range(n): for j in range(W): if CMAP[i][j]=='#': CMAP[i][j]='.' else: CMAP[i][j]='#' else: for i in range(H): for j in range(n): if CMAP[i][j]=='#': CMAP[i][j]='.' else: CMAP[i][j]='#' f = True for i in range(H): for j in range(W): if CMAP[0][0]!=CMAP[i][j]: f=False if f: print('Yes') exit() print('No')