#include <iostream>
using namespace std;
const int N = 1010;
int b[N+1];
void init()
{
for(int i=1; i<=N; i++) {
b[i] = i;
}
}
int find_set(int x)
{
if(x != b[x]) b[x] = find_set(b[x]);
return b[x];
}
int find_plus(int x)
{
int r = x;
while(r != b[r]) r = b[r];
int i = x, j;
while(i != r) {
j = b[i];
b[i] = r;
i = j;
}
return r;
}
void union_set(int x, int y)
{
x = find_set(x); y = find_set(y);
if(x != y) b[x] = b[y];
}
int h[N+1];
void union_plus(int x, int y)
{
x = find_set(x); y = find_set(y);
if(h[x] == h[y]) {
h[x] = h[x] + 1;
b[y] = x;
}
else {
if(h[x] < h[y]) b[x] = y;
else b[y] = x;
}
}
int main()
{
int t; cin >> t;
while(t--) {
init();
int n, m; cin >> n >> m;
for(int i=1; i<=m; i++) {
int l, r; cin >> l >> r;
union_set(l, r);
}
int ans = 0;
for(int i=1; i<=n; i++) {
if(b[i] == i) ans++;
}
cout << ans << endl;
}
return 0;
}