#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> v(n + 1);
for (int _ = 1; _ <= k; _++) {
vector<int> c(n + 1);
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
bool ok = true;
stack<int> st;
int cnt = 1;
for (int i = 1; i <= n; i++) {
if (c[i] == cnt) {
cnt++;
} else {
//先看看货架顶端的一箱是不是下一个要装填的颜色,如果是就取下来装填
while (st.size() && st.top() == cnt) {
cnt++; st.pop();
}
st.push(c[i]);
if (st.size() > m) {
ok = false;
break;
}
}
}
while (st.size()) {
if (st.top() == cnt) {
cnt++;
st.pop();
}
else {
ok = false;
break;
}
}
//cout << cnt << "\n";
if (ok) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
return 0;
}