#include <iostream>
using namespace std;
int main() {
int n, m, mt[1001][1001];
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> mt[i][j];
}
}
int k, wanted_value;
cin >> k;
for (int query = 1; query <= k; query++) {
cin >> wanted_value;
int found = 0;
for (int i = 1; i <= n && !found; ++i) {
if (mt[i][1] <= wanted_value && wanted_value <= mt[i][m]) {
int left_col = 1, right_col = m;
while (left_col < right_col) {
int mid_col = (left_col + right_col) / 2;
if (mt[i][mid_col] < wanted_value) {
left_col = mid_col + 1;
} else {
right_col = mid_col;
}
}
if (mt[i][left_col] == wanted_value) {
found = 1;
}
}
}
if (found) {
cout << "DA" << '\n';
} else {
cout << "NU" << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgbSwgbXRbMTAwMV1bMTAwMV07CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gbTsgKytqKSB7CiAgICAgICAgICAgIGNpbiA+PiBtdFtpXVtqXTsKCQl9Cgl9CiAgICBpbnQgaywgd2FudGVkX3ZhbHVlOwogICAgY2luID4+IGs7CiAgICBmb3IgKGludCBxdWVyeSA9IDE7IHF1ZXJ5IDw9IGs7IHF1ZXJ5KyspIHsKICAgICAgICBjaW4gPj4gd2FudGVkX3ZhbHVlOwogICAgICAgIGludCBmb3VuZCA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbiAmJiAhZm91bmQ7ICsraSkgewogICAgICAgICAgICBpZiAobXRbaV1bMV0gPD0gd2FudGVkX3ZhbHVlICYmIHdhbnRlZF92YWx1ZSA8PSBtdFtpXVttXSkgewogICAgICAgICAgICAgICAgaW50IGxlZnRfY29sID0gMSwgcmlnaHRfY29sID0gbTsKICAgICAgICAgICAgICAgIHdoaWxlIChsZWZ0X2NvbCA8IHJpZ2h0X2NvbCkgewoJCQkJCWludCBtaWRfY29sID0gKGxlZnRfY29sICsgcmlnaHRfY29sKSAvIDI7CgkJCQkJaWYgKG10W2ldW21pZF9jb2xdIDwgd2FudGVkX3ZhbHVlKSB7CgkJCQkJCWxlZnRfY29sID0gbWlkX2NvbCArIDE7CgkJCQkJfSBlbHNlIHsKCQkJCQkJcmlnaHRfY29sID0gbWlkX2NvbDsKCQkJCQl9CgkJCQl9CgkJCQlpZiAobXRbaV1bbGVmdF9jb2xdID09IHdhbnRlZF92YWx1ZSkgewoJCQkJCWZvdW5kID0gMTsKCQkJCX0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZm91bmQpIHsKICAgICAgICAgICAgY291dCA8PCAiREEiIDw8ICdcbic7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY291dCA8PCAiTlUiIDw8ICdcbic7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0K