/*
In the name of Allah, Most Gracious, Most Merciful
*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***
//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{
ll vertex,edge,a,b;
cin>>vertex>>edge;
vector<vector<ll> >v(vertex+1);
vector<ll>visited(vertex+1,0);
fn(i,edge)
{
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
stack<ll>q;
q.push(a);
while(!q.empty())
{
ll s = q.top();
q.pop();
fn(i,v[s].size())
if(!visited[v[s][i]])
q.push(v[s][i]), vertex--;
visited[s] = 1;
}
cout<<vertex<<endl;
}
int main()
{
IOS;
ll tc;
cin>>tc;
while(tc--)
{
solve();
}
return 0;
}
LyoKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBJbiB0aGUgbmFtZSBvZiBBbGxhaCwgTW9zdCBHcmFjaW91cywgTW9zdCBNZXJjaWZ1bAoKCiovCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlPG51bWVyaWM+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyoqKiBjb25zdGFudCB2YWx1ZSAqKioKY29uc3QgbG9uZyBkb3VibGUgUEkgPSAzLjE0MTU5MjY1MzU4OTc5MzIzODsKY29uc3QgZG91YmxlIEVQUyA9IDFlLTYgOwovLyoqKiBjb25zdGFudCB2YWx1ZSAqKioKCi8vKioqKioqIGRlZmluZSAqKioqKioqKgojZGVmaW5l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