//题意自己看,不会度娘
#include <stdio.h>
#include <string.h>
int a[1050];
int merge(int x)
{int r=x;while(a[r]!=r) r=a[r];return r;
}
void findx(int x,int y)
{int fx=merge(x);int fy=merge(y);if(fx!=fy)a[fx]=fy;
}
int main(int argc, char *argv[])
{int t;int n,m,i;int x,y;int flag;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=1;i<=n;i++)a[i]=i;for(scanf("%d",&m);m>0;m--){scanf("%d %d",&x,&y);findx(x,y);}for(flag=0,i=1;i<=n;i++)if(a[i]==i)flag++;printf("%d\n",flag); } return 0;
}
//Start-ZJ
//2017/11/14/19:42