#include "bits/stdc++.h"
using namespace std;
const int INF = (int)1e9+7;
int get_mask() {
int P;
cin >> P;
int mask = 0;
for (int i=0; i<P; i++) {
int E;
cin >> E;
mask |= (1<<(E-1));
}
return mask;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N, K, Q;
cin >> N >> K >> Q;
vector <pair <int, int>> dp(1<<K, make_pair(INF, -1));
for (int i=0; i<N; i++) {
int C;
cin >> C;
int mask = get_mask();
dp[mask] = min(dp[mask], make_pair(C, i));
}
for (int i=0; i<K; i++) {
for (int mask=0; mask<(1<<K); mask++) {
if (mask & (1<<i)) {
dp[mask ^ (1<<i)] = min(dp[mask ^ (1<<i)], dp[mask]);
}
}
}
for (int i=0; i<Q; i++) {
int car = dp[get_mask()].second;
if (car == -1) cout << "NIE\n";
else cout << (car+1) << "\n";
}
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IElORiA9IChpbnQpMWU5Kzc7CgppbnQgZ2V0X21hc2soKSB7CiAgaW50IFA7CiAgY2luID4+IFA7CiAgaW50IG1hc2sgPSAwOwogIGZvciAoaW50IGk9MDsgaTxQOyBpKyspIHsKICAgIGludCBFOwogICAgY2luID4+IEU7CiAgICBtYXNrIHw9ICgxPDwoRS0xKSk7CiAgfQogIHJldHVybiBtYXNrOwp9CgppbnQgbWFpbigpIHsKICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogIGludCBOLCBLLCBROwogIGNpbiA+PiBOID4+IEsgPj4gUTsKICB2ZWN0b3IgPHBhaXIgPGludCwgaW50Pj4gZHAoMTw8SywgbWFrZV9wYWlyKElORiwgLTEpKTsKICBmb3IgKGludCBpPTA7IGk8TjsgaSsrKSB7CiAgICBpbnQgQzsKICAgIGNpbiA+PiBDOwogICAgaW50IG1hc2sgPSBnZXRfbWFzaygpOwogICAgZHBbbWFza10gPSBtaW4oZHBbbWFza10sIG1ha2VfcGFpcihDLCBpKSk7CiAgfQogIGZvciAoaW50IGk9MDsgaTxLOyBpKyspIHsKICAgIGZvciAoaW50IG1hc2s9MDsgbWFzazwoMTw8Syk7IG1hc2srKykgewogICAgICBpZiAobWFzayAmICgxPDxpKSkgewogICAgICAgIGRwW21hc2sgXiAoMTw8aSldID0gbWluKGRwW21hc2sgXiAoMTw8aSldLCBkcFttYXNrXSk7CiAgICAgIH0KICAgIH0KICB9CiAgZm9yIChpbnQgaT0wOyBpPFE7IGkrKykgewogICAgaW50IGNhciA9IGRwW2dldF9tYXNrKCldLnNlY29uZDsKICAgIGlmIChjYXIgPT0gLTEpIGNvdXQgPDwgIk5JRVxuIjsKICAgIGVsc2UgY291dCA8PCAoY2FyKzEpIDw8ICJcbiI7CiAgfQp9Cg==
MTAgNSAxCjM5MzkxODc4NiAxCjIKMzgzNzAxMjk0IDAKCjIzOTg3NTgxMyAxCjEKNDk2NTczMzAyIDQKNSAyIDQgMwo0ODQ5MzMzOCAxCjUKMzcwNzk3Mzk1IDIKNCAxCjM0MjkxODQ4IDIKNSAzCjIzNTUyNTg0NiA1CjMgNSAxIDQgMgo5ODY5NjgyNiA1CjIgNSA0IDMgMQoxIDUKMSAyIDMgNCA1CjEKNQ==
10 5 1
393918786 1
2
383701294 0
239875813 1
1
496573302 4
5 2 4 3
48493338 1
5
370797395 2
4 1
34291848 2
5 3
235525846 5
3 5 1 4 2
98696826 5
2 5 4 3 1
1 5
1 2 3 4 5
1
5