#include using namespace std; int k; vector from[100010]; int a[100010]; int ans; int dfs(int x, int last) { int cur = a[x] ? k : 2000000000; for (auto v : from[x]) if (v != last) { int tmp = dfs(v, x); if (tmp == 0) ans++, tmp = 2000000000; tmp--; cur = min(cur, tmp); } return cur; } int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { from[i].clear(); } for (int i = 2; i <= n; i++) { int x; scanf("%d", &x); from[x].push_back(i); } for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } ans = 0; int tmp = dfs(1, 1); ans += tmp <= k; printf("%d\n", ans); } return 0; }