#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> e[200005];
vector<int> pick[200005];
int pre[200005];
int dp[200005][2];

void dfs(int u, int fa) {
    for (auto v : e[u]) {
        if (v == fa) continue;
        dfs(v, u);
    }
    // dp[i][0] root i is not on side
    // dp[i][1] root i is one of the side
    vector<pair<int, int> > tmp;
    int sum = 0;
    for (auto v : e[u]) {
        if (v == fa) continue;
        sum += dp[v][0] + 1;
        tmp.emplace_back(make_pair(-dp[v][0] - 1 + dp[v][1], v));
    }
    sort(tmp.begin(), tmp.end());
    if (tmp.size() == 0) {
        dp[u][0] = 0;
        dp[u][1] = 0;
    } else if (tmp.size() == 1) {
        dp[u][0] = dp[u][1] = min(sum, sum + tmp[0].first);
        if (tmp[0].first < 0) pre[u] = tmp[0].second;
        else pre[u] = -1;
    } else {
        dp[u][1] = min(sum, sum + tmp[0].first);
        if (tmp[0].first < 0) pre[u] = tmp[0].second;
        else pre[u] = -1;
        dp[u][0] = sum + tmp[0].first + tmp[1].first;
        pick[u].emplace_back(tmp[0].second);
        pick[u].emplace_back(tmp[1].second);
    }
    //cout << u << " " << dp[u][0] << " " << dp[u][1] << endl;
}

pair<int, int> find_ans(int u, int state, int fa) {
    int sz = 0;
    for (auto v : e[u]) {
        if (v == fa) continue;
        sz++;
    }
    pair<int, int> pa = make_pair(u, u);
    if (sz == 1) {
        int node = pre[u];
        if (node != -1) {
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == node) {
                    pa = find_ans(v, 1, u);
                    if (pa.first == v) pa.first = u;
                    else pa.second = u;
                }
            }
        } else {
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == node) continue;
                else {
                    pair<int, int> new_pa = find_ans(v, 0, u);
                    printf("%d %d %d %d\n", u, v, pa.first, new_pa.first);
                    pa = make_pair(pa.second, new_pa.second);
                }

            }
        }
    } else if (sz > 1) {
        if (state == 1) {
            int node = pre[u];
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == node) {
                    pa = find_ans(v, 1, u);
                    if (pa.second == v) pa.second = u;
                    else pa.first = u;
                    if (pa.second != u) swap(pa.first, pa.second);
                }
            }
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == node) continue;
                pair<int, int> new_pa = find_ans(v, 0, u);
                printf("%d %d %d %d\n", u, v, pa.first, new_pa.first);
                pa = make_pair(pa.second, new_pa.second);
                if (pa.second != u) swap(pa.first, pa.second);
            }
        } else {
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == pick[u][0] || v == pick[u][1]) {
                    pair<int, int> pa1 = find_ans(v, 1, u);
                    int node = pa1.first;
                    if (pa1.first == v) node = pa1.second;
                    if (pa.first == u) pa.first = node;
                    else pa.second = node;
                }
            }
            for (auto v : e[u]) {
                if (v == fa) continue;
                if (v == pick[u][0] || v == pick[u][1]) continue;
                pair<int, int> new_pa = find_ans(v, 0, u);
                printf("%d %d %d %d\n", u, v, pa.first, new_pa.first);
                pa = make_pair(pa.second, new_pa.second);
            }
        }
    }
    //cout << u << " " << state << " " << pa.first << " " << pa.second << endl;
    return pa;
}

int main(void) {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        scanf("%d", &n);
        for (int i = 1;i <= n;i++) {
            e[i].clear();
            pick[i].clear();
        }
        for (int i = 0;i < n - 1;i++) {
            int u, v;
            scanf("%d %d", &u, &v);
            e[u].emplace_back(v);
            e[v].emplace_back(u);
        }
        dfs(1, -1);
        printf("%d\n", min(dp[1][0], dp[1][1]));
        if (dp[1][0] > dp[1][1]) find_ans(1, 1, -1);
        else find_ans(1, 0, -1);
    }
    return 0;
}