#include <iostream>
#include <vector>
using namespace std;

const int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        // Allocate array for depth; vertices are numbered 1..n.
        vector<int> depth(n + 1, 0); // root has depth 0
        int max_depth = 0;

        // Read parent for vertices 2..n and compute depth.
        for (int i = 2; i <= n; i++) {
            int p;
            cin >> p;
            depth[i] = depth[p] + 1;
            if (depth[i] > max_depth) {
                max_depth = depth[i];
            }
        }

        // Count vertices by depth (for depths >= 1).
        vector<long long> cnt(max_depth + 1, 0);
        for (int i = 2; i <= n; i++) {
            cnt[depth[i]]++;
        }

        // S[d] = sum of f(v) for all v at depth d, for d >= 1.
        vector<long long> S(max_depth + 2, 0);
        // Base case: deepest level
        S[max_depth] = cnt[max_depth] % MOD;

        // Use recurrence: S[d] = cnt[d] + (cnt[d] - 1) * S[d+1]
        for (int d = max_depth - 1; d >= 1; d--) {
            long long ways = cnt[d] % MOD;
            long long factor = (cnt[d] - 1) % MOD;
            if (factor < 0) {
                factor += MOD; // not needed as cnt[d] >= 1 in a tree
            }
            S[d] = (ways + (factor * S[d + 1]) % MOD) % MOD;
        }

        // f(1) = 1 (the sequence with just root) plus sequences from moves from the root.
        long long result = (1 + S[1]) % MOD;
        cout << result << "\n";
    }

    return 0;
}