#include
#define N 1001
struct d{
int x;
int y;
}buf[N];
int parent[N];
int find(int x) {
return x==parent[x] ? x : find(parent[x]);
}
void uni(int x, int y) {
int a = find(x);
int b = find(y);
if(a==b)
return ;
parent[a] = b;
}
int main() {
int t, n, m, i, ans;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
for(i=0; i