#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";
        }
    }
}