#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=1000+10;
int n,father[MAXN];
void init(){
for(int i=1;i<=n;i++){
father[i]=i;
}
}
int getfather(int a){
int r;
r=a;
while(r!=father[r]){
r=father[r];
}
int i=a;
while(i!=father[i]){
i=father[i];
father[i]=r;
}
return r;
/*
if(a!=father[a]){
father[a]=getfather(father[a]);
}
return a;
*/
}
void Union(int a,int b){
int fx=getfather(a);
int fy=getfather(b);
if(fx!=fy){
father[fx]=fy;
}
}
int main()
{
int ct,m;
scanf("%d",&ct);
for(int i=0;i<ct;i++){
int cnt=0;
scanf("%d %d",&n,&m);
init();
for(int j=0;j<m;j++){
int a,b;
scanf("%d %d",&a,&b);
Union(a,b);
}
for(int k=1;k<=n;k++){
if(k==father[k]){
cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}