#include<stdio.h> int father[1001]; int find(int a) { while(father[a]>0) { a=father[a]; } return a; } int main() { int n,m,t,i,a,b,num; scanf("%d",&t); while(t--) { num=0; scanf("%d%d",&m,&n); for(i=1;i<=m;++i) father[i]=-1; for(i=1;i<=n;++i) { scanf("%d%d",&a,&b); a=find(a); b=find(b); if(a!=b) father[a]=b; } for(i=1;i<=m;++i) if(father[i]<0) ++num; printf("%d\n",num); } return 0; }