#include using namespace std; typedef long long ll; typedef pair PII; const int maxn=111111,mod=998244353; #define fi first #define se second #define MP make_pair #define PB push_back #define lson o<<1,l,mid #define rson o<<1|1,mid+1,r #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define ROF(i,a,b) for(int i=(a);i>=(b);i--) #define MEM(x,v) memset(x,v,sizeof(x)) inline ll read(){ char ch=getchar();ll x=0,f=0; while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar(); while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return f?-x:x; } inline int qpow(int a,int b){ int ans=1; for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod; return ans; } int n,k,fa[maxn],f[maxn],el,head[maxn],to[maxn],nxt[maxn],ans; inline void add(int u,int v){ to[++el]=v;nxt[el]=head[u];head[u]=el; } void dfs(int u){ for(int i=head[u];i;i=nxt[i]){ int v=to[i]; dfs(v); f[u]=max(f[u],f[v]+1); } if(f[u]==k) f[u]=-1e9,ans++; } void clear(){ FOR(i,1,el) to[i]=nxt[i]=0; FOR(i,1,n) head[i]=0; ans=el=0; } void solve(){ n=read();k=read(); FOR(i,2,n) add(read(),i); FOR(i,1,n) f[i]=read()?0:-1e9; dfs(1); if(f[1]>=0) ans++; printf("%d\n",ans); clear(); } int main(){ int T=read(); while(T--) solve(); }