m,n,k = map(int,input().split())
for _ in range(k):
stack = []
val = 1
flag = True
for x in map(int,input().split()):
# 如果栈为空或者栈顶元素不等于x,进栈直至栈顶元素 == x
while not stack or (stack[-1] != x and len(stack) < m):
stack.append(val)
val += 1
if stack[-1] == x: # 如果栈顶元素等于x,则出栈
stack.pop()
else: # 否则肯定是len(stack) >= m了,该序列不可能是该栈的弹出序列
flag = False
break
if flag:
print("YES")
else:
print("NO")