#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(){
int M,N,K,seq[1010];
scanf("%d%d%d",&M,&N,&K);
for(int i=0;i<K;i++){
bool ans=true;
stack<int> s;
queue<int> q;
for(int j=0;j<N;j++){
int temp;
scanf("%d",&temp);
q.push(temp);
}
for(int k=1;k<=N;k++){
s.push(k);
if(s.size()>M) ans=false;
while(!s.empty()&&!q.empty()&&s.top()==q.front()){
s.pop();
q.pop();
continue;
}
}
if(!s.empty()) ans=false;
if(ans) printf("YES\n");
else printf("NO\n");
}
return 0;
}
#include <iostream>
#include <stack>
using namespace std;
int M,N,K;
int main(){
scanf("%d%d%d",&M,&N,&K);
for(int i=0;i<K;i++){
stack<int> s;
bool ans=true;
s.push(1);
int now=2;
for(int j=1;j<=N;j++){
int temp;
scanf("%d",&temp);
while((!s.empty()&&temp!=s.top())||s.empty()){
if(now>N) ans=false;
s.push(now++);
if(s.size()>M) ans=false;
if(!ans) break;
}
if(temp==s.top()) s.pop();
}
if(!s.empty()||ans==false) printf("NO\n");
else printf("YES\n");
}
return 0;
}