#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define ll  long long
#define vi  vector<ll >
#define vvi vector<vi >
#define all(x) x.begin(), x.end()

ll n, m;
vi st, u;

ll f() {
    cin >> n >> m;
    st.assign(n, 0);
    u.assign(n, 1);
    vector<multiset<ll> > g(n);
    for (ll i = 0; i < m; ++i) {
        ll a, b; cin >> a >> b; --a; --b;
        g[a].insert(b); ++st[a];
        g[b].insert(a); ++st[b];
    }
    set<pair<ll, ll> > se;
    for (ll v = 0; v < n; ++v)
        se.insert({st[v], v});
    ll res = 0;
    while (!se.empty()) {
        ++res;
        vi w;
        ll val = (--se.end())->first;
        while (!se.empty() && (--se.end())->first == val) {
            w.pb((--se.end())->second);
            se.erase(--se.end());
            u[w.back()] = 0;
        }
        for (auto v : w) {
            for (auto to : g[v]) {
                if (u[to]) {
                    g[to].erase(v);
                    se.erase({st[to], to});
                    --st[to];
                    se.insert({st[to], to});
                }
            }
        }
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll t; cin >> t;
    while (t--) {
        cout << f() << "\n";
    }

    return 0;
}
