#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll, ll>

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 998244353;

ll b_pow(ll n, ll st) {
    ll ans = 1;
    while (st > 0) {
        if (st % 2) {
            ans *= n;
            ans%=mod;
            st--;
        }
        else {
            st/=2;
            n*=n;
            n%=mod;
        }
    }
    return ans;
}

ll sz[1000100];

vector<int> g[1000100];

void dfs(ll v, ll pr) {
    sz[v] = 1;
    for (auto to : g[v]) {
        if (to == pr) continue;
        dfs(to, v);
        sz[v] += sz[to];
    }
}

void solve() {
    ll n, k;
    cin >> n >> k;
    for (int i = 2; i <= n; i++) {
        ll d;
        cin >> d;
        g[d].pb(i);
    }
    dfs(1, 0);
    for (int i = 0; i < k; i++) {
        ll d;
        cin >> d;
        ll sum = 1;
        for (auto to : g[d]) {
            sum *= b_pow(2, sz[to]);
            sum %= mod;
        }
        cout << (sum + 1) % mod << ' ';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
