This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 1e5 + 2;
const int Mod = 1e9 + 7;///lon
const int INF = 2e9;
const ll BASE = 137;
const int szBL = 200;
int n, m, Q;
vector<int> ke[N];
vector<pii> dp[N];
int vis[N];
int dd[N];
int f[N];
void solution () {
    cin >> n >> m >> Q;
    rep (i, 1, m) {
        int u, v;
        cin >> u >> v;
        ke[v].pb(u);
    }
    rep (u, 1, n) {
        static vector<pii> vec; vec = {MP(0, u)};
        iter (&v, ke[u]) {
            iter (&id, dp[v]) vec.pb({id.fs + 1, id.se});
        }
        sort (ALL(vec), greater<pii>());
        iter (&id, vec) {
            if (!dd[id.se]) dp[u].pb(id);
            dd[id.se] = 1;
        }
        iter (&id, vec) dd[id.se] = 0;
    }
    rep (q, 1, Q) {
        int T, Y;
        cin >> T >> Y;
        static int step = 0; ++step;
        rep (i, 1, Y) {
            int X;
            cin >> X;
            dd[X] = step;
        }
        if (Y < szBL) {
            bool ok = 0;
            iter (&id, dp[T]) {
                if (dd[id.se] != step) {
                    cout << id.fs <<"\n";
                    ok = 1;
                    break;
                }
            }
            if (!ok) {
                cout << -1 <<"\n";
            }
        }
        else {
            reb (u, n, 1) {
                if (u == T) f[u] = 1;
                if (!f[u])
                    continue;
                iter (&v, ke[u]) {
                    f[v] = max(f[v], f[u] + 1);
                }
            }
            int res = 0;
            rep (i, 1, n) {
                if (dd[i] != step)
                    res = max(res, f[i]);
                f[i] = 0;
            }
            cout << res - 1 <<"\n";
        }
    }
}
#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
main () {
//    file("creature");
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +12
*/
Compilation message (stderr)
bitaro.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main () {
      | ^~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |