#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
vector <int> G[105];
ll dp[105][1005];
int n,m,p;
bool v[105];
void dfs(int u){
v[u] = 1;
for(int i = 1; i<=m; ++i){
dp[u][i] = 1;
}
for(int i = 0; i<(int)G[u].size(); ++i){
if(!v[G[u][i]]){
int v = G[u][i];
dfs(v);
for(int j = 1; j<=m; ++j){
ll tot = 0;
for(int k = 1; k<=m; ++k){
if(abs(j-k)>=p){
tot = (tot+dp[v][k])%MOD;
}
}
dp[u][j] = 1LL*dp[u][j]*tot%MOD;
}
}
}
v[u] = 0;
}
int main(){
int t; cin >> t;
while(t--){
memset(G,0,sizeof(G));
cin >> n >> m >> p;
for(int i=1;i<n;++i){
int u,v; cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1);
ll ans = 0;
for(int i = 1; i<=m; ++i){
ans = (ans+dp[1][i])%MOD;
}
cout << ans << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7Cgpjb25zdCBsbCBNT0QgPSAxZTkrNzsKCnZlY3RvciA8aW50PiBHWzEwNV07CmxsIGRwWzEwNV1bMTAwNV07CmludCBuLG0scDsKYm9vbCB2WzEwNV07Cgp2b2lkIGRmcyhpbnQgdSl7CiAgICB2W3VdID0gMTsKICAgIGZvcihpbnQgaSA9IDE7IGk8PW07ICsraSl7CiAgICAgICAgZHBbdV1baV0gPSAxOwogICAgfQogICAgZm9yKGludCBpID0gMDsgaTwoaW50KUdbdV0uc2l6ZSgpOyArK2kpewogICAgICAgIGlmKCF2W0dbdV1baV1dKXsKICAgICAgICAgICAgaW50IHYgPSBHW3VdW2ldOwogICAgICAgICAgICBkZnModik7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDE7IGo8PW07ICsrail7CiAgICAgICAgICAgICAgICBsbCB0b3QgPSAwOwogICAgICAgICAgICAgICAgZm9yKGludCBrID0gMTsgazw9bTsgKytrKXsKICAgICAgICAgICAgICAgICAgICBpZihhYnMoai1rKT49cCl7CiAgICAgICAgICAgICAgICAgICAgICAgIHRvdCA9ICh0b3QrZHBbdl1ba10pJU1PRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBkcFt1XVtqXSA9IDFMTCpkcFt1XVtqXSp0b3QlTU9EOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgdlt1XSA9IDA7Cn0KCmludCBtYWluKCl7CiAgICBpbnQgdDsgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIG1lbXNldChHLDAsc2l6ZW9mKEcpKTsKICAgICAgICBjaW4gPj4gbiA+PiBtID4+IHA7CiAgICAgICAgZm9yKGludCBpPTE7aTxuOysraSl7CiAgICAgICAgICAgIGludCB1LHY7IGNpbiA+PiB1ID4+IHY7CiAgICAgICAgICAgIEdbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgICAgICBHW3ZdLnB1c2hfYmFjayh1KTsKICAgICAgICB9CiAgICAgICAgZGZzKDEpOwogICAgICAgIGxsIGFucyA9IDA7CiAgICAgICAgZm9yKGludCBpID0gMTsgaTw9bTsgKytpKXsKICAgICAgICAgICAgYW5zID0gKGFucytkcFsxXVtpXSklTU9EOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0=