#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
void solve(int tc) {
int n, q;
cin >> n >> q;
vector<vector<int>> tr(n + 1);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
tr[u].push_back(v);
tr[v].push_back(u);
}
vector<int> vis(n + 1, 0);
vector<int> level(n + 1, 0);
queue<int> qu;
qu.push(1);
vis[1] = 1;
while (!qu.empty()) {
int now = qu.front();
qu.pop();
for (auto &it : tr[now]) {
if (!vis[it]) {
qu.push(it);
vis[it] = 1;
level[it] = level[now] + 1;
}
}
}
sort(level.begin() + 1, level.end());
for (int i = 1; i <= n; i++) {
int x = upper_bound(level.begin(), level.end(), i) - level.begin();
cout << x << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
for (int i = 1; i <= tc; i++) {
solve(i);
}
return 0;
}