#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> ipair;

const int MAXN = 200200;

int n, m;
multiset<int> gr[MAXN];

void init() {
    for (int v = 0; v < n; ++v)
        gr[v].clear();
}

void build() {
}

int solve() {
    int ans = 0, killed = 0;
    while (killed < n) {
        int ma = max_element(gr, gr + n, [](const multiset<int>& a, const multiset<int>& b) {
            return a.size() < b.size(); 
        })->size();
        vector<int> bad;
        for (int v = 0; v < n; ++v)
            if (gr[v].size() == ma) bad.push_back(v);
        for (int v: bad) {
            for (int u: gr[v])
                gr[u].erase(v);
            gr[v].clear();
        }
        killed += bad.size();
        ++ans;
    }
    return ans;
}

int main() {
    int t; cin >> t;
    while (t--) {
        cin >> n >> m;
        init();
        for (int j = 0; j < m; ++j) {
            int v, u; cin >> v >> u, --v, --u;
            gr[v].insert(u);
            gr[u].insert(v);
        }
        build();
        cout << solve() << endl;
    }
}