#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <ctime>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::getline;
using std::make_pair;
using std::greater;
const int MAXN(1010);
const int MAXE(2010);
int fa[1010];
struct EDGE
{
int v;
EDGE *next;
};
int count[MAXN];
EDGE *first[MAXN];
EDGE edge[MAXE];
EDGE *rear;
void init()
{
memset(first, 0, sizeof(first));
memset(count, 0, sizeof(count));
rear = edge;
}
void insert(int tu, int tv)
{
rear->v = tv;
rear->next = first[tu];
first[tu] = rear++;
++count[tu];
}
int n, s, limit;
vector<int> node[MAXN];
void dfs1(int tf, int cur, int dep)
{
fa[cur] = tf;
if(count[cur] == 1 && dep > limit)
node[dep].push_back(cur);
for(EDGE *i = first[cur]; i; i = i->next)
if(i->v != tf)
dfs1(cur, i->v, dep+1);
}
bool cover[MAXN];
void dfs2(int tf, int cur, int dep)
{
if(dep > limit)
return;
cover[cur] = true;
for(EDGE *i = first[cur]; i; i = i->next)
if(i->v != tf)
dfs2(cur, i->v, dep+1);
}
int solve()
{
memset(cover, 0, sizeof(cover));
int ret = 0;
for(int i = n-1; i > limit; --i)
{
int ts = node[i].size();
for(int j = 0; j < ts; ++j)
if(!cover[node[i][j]])
{
++ret;
int tf = node[i][j];
for(int k = 0; k < limit; ++k)
tf = fa[tf];
dfs2(-1, tf, 0);
}
}
return ret;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
init();
scanf("%d%d%d", &n, &s, &limit);
for(int i = 0; i <= n; ++i)
node[i].clear();
int tu, tv;
for(int i = 1; i < n; ++i)
{
scanf("%d%d", &tu, &tv);
insert(tu, tv);
insert(tv, tu);
}
dfs1(-1, s, 0);
printf("%d\n", solve());
}
return 0;
}