.....................................................................................................................................................................................................................

#include <stdio.h>

struct a{

int col,bi,c,data;

}p[205][205];//c for component number ,col for coloring ,bi for bicoloring,data for is there a edge

int v,maxi,elem,comp;

void visit(int u ){

int i;

p.col=1;

p.c=comp;

if(elem!=-1)

++elem;//elem for number of elements in a component return -1 if bicoloring not possible for that component

for(i=1;i<=v;i++)

{

if( p

*.data==1 && p*

*.col==0 )*

{

p{

p

*.bi =1-p.bi;*

visit(i);

}

else if( pvisit(i);

}

else if( p

*.c== p.c && p**.col==1 && p**.data==1 && p[i][i].bi == p[u][u].bi)*

{

elem=-1;

}

}

p[u][u].col=2;

}

void dfs(){

int i;

maxi=0;

comp=0;

for(i=1;i<=v;i++)

{

p[i][i].col=0;

p[i][i].c=-1;

p[i][i].bi=-1;

}

for(i=1;i<=v;i++)

{

elem=0;

if(p[i][i].col==0)

{

p[i][i].bi=0;

++comp;

visit(i);

if(elem!=-1)

{

if(elem%2==0)

maxi=maxi+elem/2;

else

maxi =maxi + elem/2+1;

}//if

}//if

}//for

}

void main(){

long int test;

int x,y,n,i,j;

scanf("%ld\n",&test);

while(test-->0){

scanf("%d",&n);

for(i=1;i<=n;i++)

for(j=1;j<=n;j++){

p[i][j].data=0;

}

v=n;

for(i=1;i<=n;i++){

scanf("%d",&x);

while(x-->0)

{

scanf("%d",&y);

if(y>n)

continue;

p[i][y].data=1;

p[y][i].data=1;

}

}

dfs();

if(test>1)

printf("%d\n",maxi);

else

printf("%d",maxi);

}

}{

elem=-1;

}

}

p[u][u].col=2;

}

void dfs(){

int i;

maxi=0;

comp=0;

for(i=1;i<=v;i++)

{

p[i][i].col=0;

p[i][i].c=-1;

p[i][i].bi=-1;

}

for(i=1;i<=v;i++)

{

elem=0;

if(p[i][i].col==0)

{

p[i][i].bi=0;

++comp;

visit(i);

if(elem!=-1)

{

if(elem%2==0)

maxi=maxi+elem/2;

else

maxi =maxi + elem/2+1;

}//if

}//if

}//for

}

void main(){

long int test;

int x,y,n,i,j;

scanf("%ld\n",&test);

while(test-->0){

scanf("%d",&n);

for(i=1;i<=n;i++)

for(j=1;j<=n;j++){

p[i][j].data=0;

}

v=n;

for(i=1;i<=n;i++){

scanf("%d",&x);

while(x-->0)

{

scanf("%d",&y);

if(y>n)

continue;

p[i][y].data=1;

p[y][i].data=1;

}

}

dfs();

if(test>1)

printf("%d\n",maxi);

else

printf("%d",maxi);

}

}