%%%jiry_2
也可以这样:http://blog.csdn.net/dwylkz/article/details/9749827
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int N=50005;
const int K=505;
const int P=10007;
struct edge{
int u,v,next;
}G[N<<1];
int head[N],inum;
inline void add(int u,int v,int p){
G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}
inline void add(int &x,int y){
x+=y; while (x>=P) x-=P;
}
int S[K][K];
inline void Pre(){
S[0][0]=1;
for (int i=1;i<=500;i++)
for (int k=1;k<=500;k++)
add(S[i][k],S[i-1][k]*k%P+S[i-1][k-1]);
}
int n,k,ans;
int f1[N][K],f2[N][K];
int tmp[K],tem[K],sum[K];
inline void trans(int *f){
for (int j=0;j<=k;j++)
add(tmp[j],f[j]+(j?j*f[j-1]%P:0));
}
#define V G[p].v
inline void dfs1(int u,int fa){
f1[u][0]=1;
for (int p=head[u];p;p=G[p].next)
if (V!=fa){
dfs1(V,u);
cl(tmp); trans(f1[V]);
for (int j=0;j<=k;j++) add(f1[u][j],tmp[j]);
}
}
inline void dfs2(int u,int fa){
if (fa) {
cl(tmp); trans(f2[fa]);
for (int j=0;j<=k;j++) add(f2[u][j],tmp[j]);
}
cl(tmp); trans(f1[u]);
for (int j=0;j<=k;j++) sum[j]=tmp[j];
for (int p=head[u];p;p=G[p].next)
if (V!=fa){
cl(tmp); trans(f1[V]);
for (int j=0;j<=k;j++) tem[j]=tmp[j];
cl(tmp); trans(tem);
for (int j=0;j<=k;j++) add(f2[V][j],sum[j]-tmp[j]+P);
}
for (int p=head[u];p;p=G[p].next)
if (V!=fa)
dfs2(V,u);
}
int main(){
int T,iu,iv;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
Pre();
read(T);
while (T--){
read(n); read(k);
for (int i=1;i<n;i++)
read(iu),read(iv),add(iu,iv,++inum),add(iv,iu,++inum);
dfs1(1,0);
dfs2(1,0);
for (int i=1;i<=n;i++)
{
ans=0;
for (int j=0;j<=k;j++)
add(ans,((f1[i][j]+f2[i][j])%P)*S[k][j]%P);
printf("%d\n",ans);
}
cl(head); inum=0;
for (int i=1;i<=n;i++) cl(f1[i]),cl(f2[i]);
}
return 0;
}
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x)
{
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
void Uncompress(FILE *infile, FILE *outfile)
{ int N, k, L, i, now, A, B, Q, tmp;
fscanf(infile, "%d%d%d", &N, &k, &L);
fscanf(infile, "%d%d%d%d", &now, &A, &B, &Q);
fprintf(outfile, "%d %d\n", N, k);
for (i = 1; i < N; i ++) { now = (now * A + B) % Q; tmp = (i < L) ? i : L; fprintf(outfile, "%d %d\n", i - now % tmp, i + 1);
}
}
const int N=50005;
const int K=155;
const int P=10007;
struct edge{
int u,v,next;
}G[N<<1];
int head[N],inum;
inline void add(int u,int v,int p){
G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}
inline void add(int &x,int y){
x+=y; while (x>=P) x-=P;
}
int S[K][K];
inline void Pre(){
S[0][0]=1;
for (int i=1;i<=150;i++)
for (int k=1;k<=150;k++)
add(S[i][k],S[i-1][k]*k%P+S[i-1][k-1]);
}
int n,k,ans;
int f1[N][K],f2[N][K];
int tmp[K],tem[K],sum[K];
inline void trans(int *f){
for (int j=0;j<=k;j++)
add(tmp[j],f[j]+(j?j*f[j-1]%P:0));
}
#define V G[p].v
inline void dfs1(int u,int fa){
f1[u][0]=1;
for (int p=head[u];p;p=G[p].next)
if (V!=fa){
dfs1(V,u);
cl(tmp); trans(f1[V]);
for (int j=0;j<=k;j++) add(f1[u][j],tmp[j]);
}
}
inline void dfs2(int u,int fa){
if (fa) {
cl(tmp); trans(f2[fa]);
for (int j=0;j<=k;j++) add(f2[u][j],tmp[j]);
}
cl(tmp); trans(f1[u]);
for (int j=0;j<=k;j++) sum[j]=tmp[j];
for (int p=head[u];p;p=G[p].next)
if (V!=fa){
cl(tmp); trans(f1[V]);
for (int j=0;j<=k;j++) tem[j]=tmp[j];
cl(tmp); trans(tem);
for (int j=0;j<=k;j++) add(f2[V][j],sum[j]-tmp[j]+P);
}
for (int p=head[u];p;p=G[p].next)
if (V!=fa)
dfs2(V,u);
}
int main(){
int iu,iv;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
Pre();
int now,A,B,Q,L;
read(n); read(k); read(L);
read(now); read(A); read(B); read(Q);
for(int i=1;i<n;i++)
{
now=(now*A+B)%Q;
iu=i-now%((i<L)?i:L),iv=i+1;
add(iu,iv,++inum),add(iv,iu,++inum);
}
dfs1(1,0);
dfs2(1,0);
for (int i=1;i<=n;i++)
{
ans=0;
for (int j=0;j<=k;j++)
add(ans,((f1[i][j]+f2[i][j])%P)*S[k][j]%P);
printf("%d\n",ans);
}
return 0;
}