#include<iostream>
using namespace std;
int pre[1005];
int n, m;
int ans;
void chu(int n)
{
	int i;
	for (i = 0; i <=n; i++) { pre[i] = i; }}int find(int x)
{
	int r;
	r = x;
	while(r ! = pre[r]) { r = pre[r]; }return r;
}
void join(int a,int b)
{
	int fa = find(a);
	int fb = find(b);
	if(fa != fb)
	{
		ans--;
		pre[fa] = fb;
	}

}
int main(a)
{
	int t;
	cin >> t;
	int k;
	while (t--)
	{
		cin >> n >> m;
		chu(n);
		ans = n;
		while (m--)
		{
			int a, b;
			cin >> a >> b;
			join(a, b);
			
		}
		cout <<ans << endl;

	}
	return 0;
}
Copy the code