#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
using namespace std;
struct node{
    ll t,n;
}edge[N<<1];
ll head[N],cn=-1,n,m,jie[N],inv[N],dp[N],ans;
pll E[N];
const ll mod=998244353;
ll read(){char c=getchar();
    ll n=0;
    while(c<'0'||c>'9')c=getchar();
    while(c<='9'&&c>='0')n=(n<<1)+(n<<3)+c-'0',c=getchar();
    return n;
}
void add(ll a,ll b){
    edge[++cn]={b,head[a]};
    head[a]=cn;
    edge[++cn]={a,head[b]};
    head[b]=cn;
}
ll qpow(ll a,ll b){ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
inline void dfs(ll f,ll la){ll i,cnt=0;
    dp[f]=1;
    for(i=head[f];~i;i=edge[i].n){
        if(edge[i].t==la)continue;
        dfs(edge[i].t,f),cnt++;
        dp[i]=dp[i]*dp[edge[i].t]%mod;
    }
    dp[f]=dp[f]*jie[cnt]%mod;
}
int main(){ll i,k,x,y,e,t;
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    e=read(),t=read();
    while(t--){memset(head,-1,sizeof(head)),cn=-1;
        n=read(),m=read(),jie[0]=1;
        for(i=1;i<n;i++){x=read(),y=read(),E[i]=mp(x,y);
            add(x,y),jie[i]=jie[i-1]*i%mod;
        }
        for(i=1;i<=m;i++){
            e=read();
            dfs(E[e].fi,E[e].se);
            ans=dp[E[e].fi];
            dfs(E[e].se,E[e].fi);
            ans=ans*dp[E[e].se]%mod;
            cout<<ans<<'\n';
        }
    }
}