//题目大致意思为建立一个有向图,用bfs实现查询L层 内的结点数目,即为转发次数
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
const int maxn=1010;struct node{int id;int layer;};
vector<node> Adj[maxn];//用邻接表实现图的存储 int bfs(int s,int L){int numForward=0;queue<node> q;bool inq[maxn]={false};node start;start.id=s;start.layer=0;q.push(start);inq[start.id]=true;while(!q.empty()){node topNode=q.front();q.pop();int u=topNode.id;for(int i=0;i<Adj[u].size();i++){node next=Adj[u][i];next.layer=topNode.layer+1;if(inq[next.id]==false&&next.layer<=L){printf("next.id==%d\n",next.id); q.push(next);inq[next.id]=true;numForward++;} }}return numForward;
}
int main(){int n,L;int numFollower,idFollower;int numQuery,s;node user;scanf("%d%d",&n,&L);for(int i=1;i<=n;i++){user.id=i;scanf("%d",&numFollower);for(int j=0;j<numFollower;j++){scanf("%d",&idFollower);Adj[idFollower].push_back(user); }}scanf("%d",&numQuery);for(int i=0;i<numQuery;i++){scanf("%d",&s);int numForward=bfs(s,L);printf("%d\n",numForward);}}