#include <bits/stdc++.h>
using namespace std;
constexpr int Spp{1<<20};
char buf[Spp],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,Spp,stdin),p1==p2)?EOF:*p1++)
template <typename T>
void read(T &x) {
char c;int f{1};
do x=(c=getchar())^48;
while (!isdigit(c)&&c!='-');
if (x==29) f=-1,x=0;
while (isdigit(c=getchar()))
x=(x*10)+(c^48);
x*=f;
}
template <typename T,typename ...Args>
void read(T& x,Args&... args) {read(x);read(args...);}
#define int long long
const int mod=998244353;
const int B=18,MAXN=1<<B;
int qmi(int a,int b,int p)
{
int res=1;
while(b)
{
if(b&1) res=1LL*res*a%p;
a=1LL*a*a%p;
b>>=1;
}
return res;
}
namespace Poly
{
#define mul(x,y) (1ll*x*y>=mod?1ll*x*y%mod:1ll*x*y)
#define minus(x,y) (1ll*x-y<0?1ll*x-y+mod:1ll*x-y)
#define plus(x,y) (1ll*x+y>=mod?1ll*x+y-mod:1ll*x+y)
#define ck(x) (x>=mod?x-mod:x)
typedef deque<int> poly;
const int G=3;
const int inv_G=qmi(G,mod-2,mod);
int RR[MAXN],deer[2][B+1][MAXN],inv[MAXN];
void init(const int t)
{
for(int p=1;p<=t;p++)
{
int buf1=qmi(G,(mod-1)/(1<<p),mod);
int buf0=qmi(inv_G,(mod-1)/(1<<p),mod);
deer[0][p][0]=deer[1][p][0]=1;
for(int i=1;i<(1<<p);i++)
{
deer[0][p][i]=1ll*deer[0][p][i-1]*buf0%mod;
deer[1][p][i]=1ll*deer[1][p][i-1]*buf1%mod;
}
}
inv[1]=1;
for(int i=2;i<(1<<t);i++) inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
}
int NTT_init(int n)
{
int limit=1,L=0;
while(limit<=n) limit<<=1,L++;
for(int i=0;i<limit;i++) RR[i]=(RR[i>>1]>>1)|((i&1)<<(L-1));
return limit;
}
void NTT(poly &A,int type,int limit)
{
A.resize(limit);
for(int i=0;i<limit;i++) if(i<RR[i]) swap(A[i],A[RR[i]]);
for(int mid=2,j=1;mid<=limit;mid<<=1,j++)
{
int len=mid>>1;
for(int pos=0;pos<limit;pos+=mid)
{
int *wn=deer[type][j];
for(int i=pos;i<pos+len;i++,wn++)
{
int tmp=1ll*(*wn)*A[i+len]%mod;
A[i+len]=ck(A[i]-tmp+mod);
A[i]=ck(A[i]+tmp);
}
}
}
if(!type) for(int i=0;i<limit;i++) A[i]=1ll*A[i]*inv[limit]%mod;
}
poly poly_mul(poly A,poly B)
{
int deg=A.size()+B.size()-1;
int limit=NTT_init(deg);
poly C(limit);
NTT(A,1,limit),NTT(B,1,limit);
for(int i=0;i<limit;i++) C[i]=1ll*A[i]*B[i]%mod;
NTT(C,0,limit);
C.resize(deg);
return C;
}
poly poly_inv(poly &f,int deg)
{
if(deg==1) return poly(1,qmi(f[0],mod-2,mod));
poly A(f.begin(),f.begin()+deg);
poly B=poly_inv(f,deg+1>>1);
int limit=NTT_init(deg<<1);
NTT(A,1,limit),NTT(B,1,limit);
for(int i=0;i<limit;i++) A[i]=B[i]*(2-1ll*A[i]*B[i]%mod+mod)%mod;
NTT(A,0,limit);
A.resize(deg);
return A;
}
poly poly_dev(poly f)
{
int n=f.size();
for(int i=1;i<n;i++) f[i-1]=1ll*f[i]*i%mod;
return f.resize(n - 1), f;
}
poly poly_idev(poly f)
{
int n=f.size();
for(int i=n-1;i;i--) f[i]=1ll*f[i - 1]*inv[i] % mod;
return f[0]=0,f;
}
poly poly_ln(poly f,int deg)
{
poly A = poly_idev(poly_mul(poly_dev(f),poly_inv(f, deg)));
return A.resize(deg),A;
}
poly poly_exp(poly &f,int deg)
{
if(deg==1) return poly(1,1);
poly B=poly_exp(f,deg+1>>1);
B.resize(deg);
poly lnB=poly_ln(B,deg);
for(int i=0;i<deg;i++)
lnB[i]=ck(f[i]-lnB[i]+mod);
int limit=NTT_init(deg<<1);
NTT(B,1,limit),NTT(lnB,1,limit);
for(int i=0;i<limit;i++) B[i]=1ll*B[i]*(1+lnB[i])%mod;
NTT(B,0,limit);
B.resize(deg);
return B;
}
poly poly_sqrt(poly &f,int deg)
{
if(deg==1) return poly(1, 1);
poly A(f.begin(),f.begin()+deg);
poly B=poly_sqrt(f,deg+1>>1);
poly IB=poly_inv(B,deg);
int limit=NTT_init(deg<<1);
NTT(A,1,limit),NTT(IB,1,limit);
for(int i=0;i<limit;i++) A[i]=1ll*A[i]*IB[i]%mod;
NTT(A,0,limit);
for(int i=0;i<deg;i++) A[i]=1ll*(A[i]+B[i])*inv[2]%mod;
A.resize(deg);
return A;
}
poly poly_pow(poly f,int k)
{
f=poly_ln(f,f.size());
for(auto &x:f) x=1ll*x*k%mod;
return poly_exp(f, f.size());
}
}
constexpr int N(1e5),b6e0{998244353};
deque<int> f[N+5];
int sz[N+5];
vector<int> e[N+5];
int n,k;
bool solve(int u) {
sz[u]=1;
int sc{0};
for (auto v:e[u]) {
e[v].erase(find(e[v].begin(),e[v].end(),u));
if (!solve(v)) return false;
sz[u]+=sz[v],sc+=(sz[v]>=k);
}
if (sz[u]<k) return;
if (sc==0) {
f[u].resize(k+2,0);
if (sz[u]<=k+1) f[u][sz[u]]=1;
} else if (sc==1) {
int s{1};
for (auto v:e[u])
if (sz[v]<k) s+=sz[v];
if (s>k+1) {
f[u].resize(k+2,0);
return false;
}
for (auto v:e[u])
if (sz[v]>=k) {
f[u]=move(f[v]);
f[u][0]=(f[u][k]+f[u][k+1])%b6e0;
while (s--) f[u].push_front(0);
while (f[u].size()>k+2) f[u].pop_back();
break;
}
} else {
f[u].resize(k+2,0);
int s{1};
for (auto v:e[u])
if (sz[v]<k) s+=sz[v];
if (s>k+1) {
return false;
}
f[u][s]=1;
for (auto v:e[u])
if (sz[v]>=k) {
deque<int> g=Poly::poly_mul(f[u],f[v]);
while (g.size()>k+2) g.pop_back();
for (int i{1};i<=k+1;++i) g[i]=(g[i]+1LL*f[u][i]*(f[v][k]+f[v][k+1]))%b6e0;
swap(f[u],g);
}
}
return true;
}
signed main() {
Poly::init(B);
int T;read(T);
while (T--) {
read(n,k);
for (int i{1};i<n;++i) {
int u,v;read(u,v);
e[u].push_back(v);
e[v].push_back(u);
}
if (solve(1)) cout<<(f[1][k]+f[1][k+1])%b6e0<<"\n";
else cout<<"0\n";
for (int i{1};i<=n;++i) {
f[i].clear();
sz[i]=1;
e[i].clear();
}
}
return 0;
}