#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<stdlib.h>
using namespace std;
const int INF =2100000000;
int pre[1010];
void Init(int n)
{
for(int i=0;i<=n;i++)
pre[i]=i;
}
int finds(int x)
{
return pre[x]==x?x:pre[x]=finds(pre[x]);
}
void jion(int x,int y)
{
int fx=finds(x);
int fy=finds(y);
pre[fy]=fx;
}
int main()
{
int n_case;
scanf("%d",&n_case);
while(n_case--)
{
int people,contect,i;
scanf("%d %d",&people,&contect);
Init(people);
for(i=1;i<=contect;i++)
{
int x,y;
scanf("%d%d",&x,&y);
jion(x,y);
}
int ans=0;
for(i=1;i<=people;i++)
{
if(pre[i]==i) ans++;
}
printf("%d\n",ans);
}
return 0;
}