#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5;
vector<int>g[N];
int dis[N];
int n, k, t, tot;
void dfs(int f, int x)
{
dis[x] = 1;
for (auto u : g[x])
{
if (u == f)continue;
dfs(x, u);
dis[x] += dis[u];
}
if (dis[x] == k)dis[x] = 0, tot++;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--)
{
memset(dis, 0, sizeof(dis));
cin >> n >> k;
for (int i = 1; i < n; i++)g[i].clear();
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
if (n % k != 0)
{
cout << "NO" << endl;
continue;
}
dfs(1, 0);
if (n / k != tot)cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}