#include <iostream>
using namespace std;
const int MAX_SIZE = 1000;
const int TEN = 10;
int main() {
int n, m, mt[MAX_SIZE + TEN][MAX_SIZE];
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> mt[i][j];
}
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int line[MAX_SIZE], ln = 0;
for (int j = 0; j < m; ++j) {
cin >> line[j];
while (mt[ln][j] < line[j] && ln <= n) {
++ln;
}
}
int similarElCheck = 1;
for (int j = 0; j < m; ++j) {
if (mt[ln][j] != line[j]) {
similarElCheck = 0;
j = m;
cout << "NU\n";
}
}
if (similarElCheck) {
cout << "DA\n";
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDsKY29uc3QgaW50IFRFTiA9IDEwOwoKaW50IG1haW4oKSB7CglpbnQgbiwgbSwgbXRbTUFYX1NJWkUgKyBURU5dW01BWF9TSVpFXTsKCWNpbiA+PiBuID4+IG07Cglmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewoJCWZvciAoaW50IGogPSAwOyBqIDwgbTsgKytqKSB7CgkJCWNpbiA+PiBtdFtpXVtqXTsKCQl9Cgl9CglpbnQgcTsKCWNpbiA+PiBxOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBxOyArK2kpIHsKCQlpbnQgbGluZVtNQVhfU0laRV0sIGxuID0gMDsKCQlmb3IgKGludCBqID0gMDsgaiA8IG07ICsraikgewoJCQljaW4gPj4gbGluZVtqXTsKCQkJd2hpbGUgKG10W2xuXVtqXSA8IGxpbmVbal0gJiYgbG4gPD0gbikgewoJCQkJKytsbjsKCQkJfSAKCQl9CgkJaW50IHNpbWlsYXJFbENoZWNrID0gMTsKCQlmb3IgKGludCBqID0gMDsgaiA8IG07ICsraikgewoJCQlpZiAobXRbbG5dW2pdICE9IGxpbmVbal0pIHsKCQkJCXNpb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