include <bits/stdc++.h>

using namespace std;

define mp make_pair

define pb push_back

define rep(i,a,b) for(int i=(a);i<=(b);i++)

define per(i,a,b) for(int i=(a);i>=(b);i--)

define cl(a) memset((a),0,sizeof(a))

ifdef HandsomeHow

define dbg(x) cerr << #x << " = " << x << endl

else

define dbg(x)

endif

typedef long long ll;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
inline void gn(long long&x){
int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
while((c=getchar())>='0'&&c<='9')x=x10+c-'0';x=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
//const double pi=acos(-1.0);
//const int mod=1000000007;
//ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
//ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=ta%mod;a=aa%mod;x>>=1;}return t;}
const int maxn = 5005;
vector<int>E[maxn];
int d[maxn];
int main(){
#ifdef HandsomeHow
freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
#endif
int n,m,Q;
gn(n);gn(m);gn(Q);
rep(i,1,m){
int x,y;
gn(x);gn(y);
E[x].pb(y);
E[y].pb(x);
}
while(Q--){
memset(d,0x3f,sizeof(d));
int t,s;
gn(t);gn(s);
queue<int>q;
rep(i,1,t){
int x;gn(x);
d[x] = 0;
q.push(x);
}
while(!q.empty()){
int p = q.front();
q.pop();
for(auto it:E[p]){
if(d[it]==inf){
d[it] = d[p]+1;
q.push(it);
}
}
}
int ans = 0;
rep(i,1,n)if(d[i]<=s)ans++;
printf("%d\n",ans);
}
return 0;
}</int></int>