#include<stdio.h>
#include<stdlib.h>
typedef enum{false,true} bool;
typedef struct stack* pst;
struct stack {
int* data;
int top;
int cnt;
int capacity;};
bool Judge(int M, int N);
bool Check(pst S, int*T, int i);
bool IsEmpty(pst S);
int Peek(pst S);
bool IsFull(pst S);voidPush(pst S);voidPop(pst S);
int main(){
int M;//capacity of stack
int N;//number of push
int K;//number of case
int flag =1;//adjust outcomescanf("%d %d %d",&M,&N,&K);while(K--){if(flag) flag =0;elseprintf("\n");if(Judge(M,N))printf("YES");elseprintf("NO");}return0;}
bool Judge(int M, int N){
bool flag =true;
int*T=(int*)malloc(N*sizeof(int));
int i;for(i =0; i <N; i++)scanf("%d",&T[i]);
pst S=(pst)malloc(sizeof(struct stack));S->capacity =M;S->cnt =0;S->top =-1;S->data =malloc(M*sizeof(int));for(i =0; i <N; i++){if(!Check(S,T, i)) flag =false;}return flag;}
bool Check(pst S,int*T,int i){while(true){if(IsEmpty(S)||Peek(S)<T[i]){if(IsFull(S))returnfalse;elsePush(S);}elseif(Peek(S)==T[i]){Pop(S);returntrue;}elsereturnfalse;}}
bool IsEmpty(pst S){if(S->top ==-1)returntrue;elsereturnfalse;}
int Peek(pst S){returnS->data[S->top];}
bool IsFull(pst S){if(S->top ==S->capacity -1)returntrue;elsereturnfalse;}voidPush(pst S){S->data[++S->top]=++S->cnt;}voidPop(pst S){S->top--;}