#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
g[y].push_back(x);
}
while (q--) {
int t, k;
cin >> t >> k;
t--;
vector<int> y(k);
for (int i = 0; i < k; i++) {
cin >> y[i];
y[i]--;
}
set<int> c(y.begin(), y.end());
vector<int> dp(n, -1e9);
dp[t] = 0;
for (int i = t; i >= 0; i--) {
for (int j : g[i]) {
dp[j] = max(dp[j], dp[i] + 1);
}
}
int ans = -1;
for (int i = 0; i <= t; i++) {
if (!c.count(i)) {
ans = max(ans, dp[i]);
}
}
cout << ans << '\n';
}
return 0;
}