/**********************************************************************************************
    ->                      @author : a_e_kasem
    ->   "Code is an art — let logic be your ink and syntax your rhythm."
***********************************************************************************************/
//*------------------------------------------------------------------------------------------*//
//                                  ﷽
//                            { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى }
//
//                     فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ
//
//                              وَما نَيلُ المَطالِبِ بِالتَمَنّي
//                               وَلَكِن تُؤخَذُ الدُنيا غِلابا
//                                     ***
//                             وَما اِستَعصى عَلى قَومٍ مَنالٌ
//                             إِذا الإِقدامُ كانَ لَهُم رِكابا
//*------------------------------------------------------------------------------------------*//
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define cinAll(a) for (auto &it : a) cin >> it
#define all(x) (x).begin(), (x).end()
#define NO  void(cout << "NO\n")
#define YES void(cout << "YES\n")
 
 
const int N = 2e5 + 5;
const long double NEG_INF = -1e300L, EPS = 1e-12L;
 
vector<int> G[N];
int sub[N], par[N];
long double logC[N];
 
void reset(int n) {
    for (int i = 1; i <= n; ++i) G[i].clear(), sub[i] = 0, par[i] = 0;
}
 
void dfsSubtree(int root = 1) {
    vector<int> order; order.reserve(N);
    stack<int> st; st.push(root); par[root] = -1;
    while (!st.empty()) {
        int u = st.top(); st.pop();
        order.push_back(u);
        for (auto v : G[u]) if (v != par[u]) par[v] = u, st.push(v);
    }
    for (int i = order.size() - 1; i >= 0; --i) {
        int u = order[i]; sub[u] = 1;
        for (auto v : G[u]) if (v != par[u]) sub[u] += sub[v];
    }
}
 
void preLogC(int n, int k) {
    for (int i = k; i <= n; ++i)
        logC[i] = lgammal(i + 1.0L) - lgammal(k + 1.0L) - lgammal(i - k + 1.0L);
}
 
void solve() {
    int n, k; cin >> n >> k;
    reset(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v; cin >> u >> v;
        G[u].push_back(v); G[v].push_back(u);
    }
    if (k == 1) return cout << n * n << '\n', void();
 
    preLogC(n, k);
    dfsSubtree();
 
    long long ans = 0;
    for (int v = 1; v <= n; ++v) {
        vector<int> comp;
        for (auto to : G[v])
            comp.push_back(to == par[v] ? n - sub[v] : sub[to]);
 
        vector<long double> B, scaled; long double mx = NEG_INF, tot = 0;
        for (int s : comp) {
            long double val = (s >= k) ? logC[s] : NEG_INF;
            B.push_back(val); mx = max(mx, val);
        }
        for (auto b : B) {
            long double x = (b <= NEG_INF/2) ? 0.0L : expl(b - mx);
            scaled.push_back(x); tot += x;
        }
 
        if (n >= k) {
            long double A = logC[n], f = (tot > 0 ? expl(mx - A) * tot : 0);
            if (f < 1.0L - EPS) ans++;
        }
 
        for (int i = 0; i < (int)comp.size(); ++i) {
            int aj = comp[i], t = n - aj;
            if (!aj || t < k) continue;
            long double A = logC[t], f = (tot - scaled[i] > 0 ? expl(mx - A) * (tot - scaled[i]) : 0);
            if (f < 1.0L - EPS) ans += aj;
        }
    }
    cout << ans << '\n';
}
 
 
void FastIO();
 
int32_t main()
{
    FastIO();
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
 
void FastIO()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}