// cre: nnhzzz - Nguyen Ngoc Hung
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <cassert>
using namespace std;
#define ll long long
#define int long long
const int MOD = 1e9+7;
const int maxn = 111;
vector<int> adj[maxn];
int dp[maxn][2LL*maxn*maxn],pre[maxn][2LL*maxn*maxn],fre[maxn][2LL*maxn*maxn];
int tmp[maxn*maxn+maxn],f[maxn];
bool v[maxn];
int n,m,k;
void dfs(int u, int dad){
for(int i = 1; i<=m; ++i){
dp[u][i] = 1;
}
for(auto v:adj[u]){
if(v!=dad){
dfs(v,u);
for(int j = 1; j<=m; ++j){
if(k>0){
dp[u][j] = 1LL*dp[u][j]*(pre[v][max(j-k,0LL)]+fre[v][min(m+1,j+k)])%MOD;
}else{
dp[u][j] = 1LL*dp[u][j]*pre[v][m]%MOD;
}
}
}
}
for(int i = 1; i<=m; i++){
pre[u][i] = (pre[u][i-1]+dp[u][i])%MOD;
}
for(int i = m; i>0; i--){
fre[u][i] = (fre[u][i+1]+dp[u][i])%MOD;
}
}
void dfs1(int u, int dad){
for(auto v:adj[u]){
if(v!=dad){
dfs1(v,u);
for(int j = 1; j<=n*k; j++){
tmp[j] = (tmp[j-1]+dp[v][j])%MOD;
}
for(int j = n*k+1; j<=n*k+k; j++){
tmp[j] = (tmp[j-1]+dp[v][n*k])%MOD;
}
for(int j = 1; j<=n*k; j++){
dp[u][j] = 1LL*dp[u][j]*((f[v]-tmp[j+k-1])%MOD+tmp[max(j-k,0LL)])%MOD;
}
}
}
for(int i = 1; i<=n*k; i++){
f[u] = (f[u]+2LL*dp[u][i])%MOD;
}
f[u] = (f[u]+1LL*dp[u][n*k]*(m-2LL*n*k))%MOD;
}
signed main(){
#define name "test"
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
int t; cin >> t;
while(t--){
memset(adj,0,sizeof(adj));
memset(pre,0,sizeof(pre));
memset(fre,0,sizeof(fre));
memset(tmp,0,sizeof(tmp));
memset(f,0,sizeof(f));
cin >> n >> m >> k;
for(int i = 2; i<=n; ++i){
int u,v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if(2LL*n*k>=m){
dfs(1,0);
cout << pre[1][m];
}else{
if(k==0){
int res = 1;
while(n--){
res = 1LL*res*m%MOD;
}
cout << res << endl;
continue;
}
for(int i = 1; i<=n; i++){
for(int j = 1; j<=m && j<=2LL*n*k; j++){
dp[i][j] = 1;
}
}
dfs1(1,0);
cout << (f[1]+MOD)%MOD;
}
cout << endl;
}
return 0;
}
Ly8gY3JlOiBubmh6enogLSBOZ3V5ZW4gTmdvYyBIdW5nCgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8aW9zPgojaW5jbHVkZSA8aW9zZndkPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpc3RyZWFtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDxsaW1pdHM+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8bG9jYWxlPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8bmV3PgojaW5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gICAgICAgICAgICBpZihrPjApewogICAgICAgICAgICAgICAgICAgIGRwW3VdW2pdID0gMUxMKmRwW3VdW2pdKihwcmVbdl1bbWF4KGotaywwTEwpXStmcmVbdl1bbWluKG0rMSxqK2spXSklTU9EOwogICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgZHBbdV1bal0gPSAxTEwqZHBbdV1bal0qcHJlW3ZdW21dJU1PRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGZvcihpbnQgaSA9IDE7IGk8PW07IGkrKyl7CiAgICAgICAgcHJlW3VdW2ldID0gKHByZVt1XVtpLTFdK2RwW3VdW2ldKSVNT0Q7CiAgICB9CiAgICBmb3IoaW50IGkgPSBtOyBpPjA7IGktLSl7CiAgICAgICAgZnJlW3VdW2ldID0gKGZyZVt1XVtpKzFdK2RwW3VdW2ldKSVNT0Q7CiAgICB9Cn0KCnZvaWQgZGZzMShpbnQgdSwgaW50IGRhZCl7CiAgICBmb3IoYXV0byB2OmFkalt1XSl7CiAgICAgICAgaWYodiE9ZGFkKXsKICAgICAgICAgICAgZGZzMSh2LHUpOwogICAgICAgICAgICBmb3IoaW50IGogPSAxOyBqPD1uKms7IGorKyl7CiAgICAgICAgICAgICAgICB0bXBbal0gPSAodG1wW2otMV0rZHBbdl1bal0pJU1PRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IoaW50IGogPSBuKmsrMTsgajw9biprK2s7IGorKyl7CiAgICAgICAgICAgICAgICB0bXBbal0gPSAodG1wW2otMV0rZHBbdl1bbiprXSklTU9EOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDE7IGo8PW4qazsgaisrKXsKICAgICAgICAgICAgICAgIGRwW3VdW2pdID0gMUxMKmRwW3VdW2pdKigoZlt2XS10bXBbaitrLTFdKSVNT0QrdG1wW21heChqLWssMExMKV0pJU1PRDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGZvcihpbnQgaSA9IDE7IGk8PW4qazsgaSsrKXsKICAgICAgICBmW3VdID0gKGZbdV0rMkxMKmRwW3VdW2ldKSVNT0Q7CiAgICB9CiAgICBmW3VdID0gKGZbdV0rMUxMKmRwW3VdW24qa10qKG0tMkxMKm4qaykpJU1PRDsKfQoKc2lnbmVkIG1haW4oKXsKICAgICNkZWZpbmUgbmFtZSAidGVzdCIKICAgIGlmKGZvcGVuKG5hbWUiLmlucCIsInIiKSl7CiAgICAgICAgZnJlb3BlbihuYW1lIi5pbnAiLCJyIixzdGRpbik7CiAgICAgICAgZnJlb3BlbihuYW1lIi5vdXQiLCJ3IixzdGRvdXQpOwogICAgfQogICAgaW50IHQ7IGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBtZW1zZXQoYWRqLDAsc2l6ZW9mKGFkaikpOwogICAgICAgIG1lbXNldChwcmUsMCxzaXplb2YocHJlKSk7CiAgICAgICAgbWVtc2V0KGZyZSwwLHNpemVvZihmcmUpKTsKICAgICAgICBtZW1zZXQodG1wLDAsc2l6ZW9mKHRtcCkpOwogICAgICAgIG1lbXNldChmLDAsc2l6ZW9mKGYpKTsKICAgICAgICBjaW4gPj4gbiA+PiBtID4+IGs7CiAgICAgICAgZm9yKGludCBpID0gMjsgaTw9bjsgKytpKXsKICAgICAgICAgICAgaW50IHUsdjsgY2luID4+IHUgPj4gdjsKICAgICAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh2KTsKICAgICAgICAgICAgYWRqW3ZdLnB1c2hfYmFjayh1KTsKICAgICAgICB9CiAgICAgICAgaWYoMkxMKm4qaz49bSl7CiAgICAgICAgICAgIGRmcygxLDApOwogICAgICAgICAgICBjb3V0IDw8IHByZVsxXVttXTsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgaWYoaz09MCl7CiAgICAgICAgICAgICAgICBpbnQgcmVzID0gMTsKICAgICAgICAgICAgICAgIHdoaWxlKG4tLSl7CiAgICAgICAgICAgICAgICAgICAgcmVzID0gMUxMKnJlcyptJU1PRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvdXQgPDwgcmVzIDw8IGVuZGw7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IoaW50IGkgPSAxOyBpPD1uOyBpKyspewogICAgICAgICAgICAgICAgZm9yKGludCBqID0gMTsgajw9bSAmJiBqPD0yTEwqbiprOyBqKyspewogICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBkZnMxKDEsMCk7CiAgICAgICAgICAgIGNvdXQgPDwgKGZbMV0rTU9EKSVNT0Q7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9