#include <bits/stdc++.h>
using namespace std;
// // Common file
// #include <ext/pb_ds/assoc_container.hpp>
// // Including tree_order_statistics_node_update
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//asd
#define MOD 1000000007
void fast() {
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
vector <vector<int>> graph;
int infect = 0, spread = 0;
void dfs(int i) {
infect += min((int)graph[i].size(), 1);
spread += max((int)graph[i].size() - 1, 0);
//cout << i << " " << min((int)graph[i].size(), 1) << " " << max((int)graph[i].size() - 1, 0) << "\n";
for(auto j: graph[i])
dfs(j);
}
int main() {
//fast();
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int t;
t = 1;
cin >> t;
while(t--) {
//cout << "hi\n";
int n;
cin >> n;
graph.assign(n+1, {});
infect = 1;
spread = 0;
for(int i = 2; i <= n; i ++) {
int a;
cin >> a;
graph[a].push_back(i);
}
dfs(1);
if(infect > spread) {
cout << infect << "\n";
} else {
cout << (long long)(1 + ceil((spread + infect - 1) / 2.0)) << "\n";
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gLy8gQ29tbW9uIGZpbGUKLy8gI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgovLyAvLyBJbmNsdWRpbmcgdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlCi8vICNpbmNsdWRlIDxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPgoKLy8gdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7Ci8vICNkZWZpbmUgb3JkZXJlZF9zZXQgdHJlZTxpbnQsIG51bGxfdHlwZSwgbGVzczxpbnQ+LCByYl90cmVlX3RhZywgdHJlZV9vcmRlcl9zdGF0aXN0aWN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ICAgICAgICAgICAgY2luID4+IGE7CiAgICAgICAgICAgIGdyYXBoW2FdLnB1c2hfYmFjayhpKTsKICAgICAgICB9CgogICAgICAgIGRmcygxKTsKCiAgICAgICAgaWYoaW5mZWN0ID4gc3ByZWFkKSB7CiAgICAgICAgICAgIGNvdXQgPDwgaW5mZWN0IDw8ICJcbiI7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY291dCA8PCAobG9uZyBsb25nKSgxICsgY2VpbCgoc3ByZWFkICsgaW5mZWN0IC0gMSkgLyAyLjApKSA8PCAiXG4iOwogICAgICAgIH0KICAgIH0KfQ==