#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 1007;
vector<int> edge[maxn],node[maxn];
int n,s,k,fa[maxn],vis[maxn];
void dfs(int cur, int father, int depth) {
fa[cur] = father;
if (edge[cur].size() == 1 && depth > k) {
node[depth].push_back(cur);
}
for (int i = 0; i < edge[cur].size(); i++) {
int t = edge[cur][i];
if (t != father) dfs(t, cur, depth + 1);
}
}
void dfs2(int cur,int father,int depth) {
vis[cur] = true;
int len = edge[cur].size();
for (int i = 0; i < len; i++) {
int t = edge[cur][i];
if (t != father && depth < k) {
dfs2(t, cur, depth + 1);
}
}
}
int GetResult() {
memset(vis, 0, sizeof(vis));
int ans = 0;
for (int i = n - 1; i > k; i--) {
for (int j = 0; j < node[i].size(); j++) {
int t = node[i][j];
if (vis[t])continue;
int father = t;
for (int l = 0; l < k; l++)father = fa[father];
dfs2(father,-1,0);
ans++;
}
}
return ans;
}
int main()
{
int t;
cin >> t;
while (t--) {
cin >> n >> s >> k;
for (int i = 0; i <= n; i++) {
edge[i].clear();
node[i].clear();
}
int a, b;
for (int i = 1; i < n; i++) {
cin >> a >> b;
edge[a].push_back(b);
edge[b].push_back(a);
}
dfs(s, -1, 0);
cout << GetResult() << endl;
}
return 0;
}