#pragma GCC optimize("O3, unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int inf = 1e9L;
const int mod = 998244353;
const int maxn = 10;

ll mod_bin_pow(ll x, ll pow) {
    if (!pow) return 1;
    ll ans = mod_bin_pow(x, pow / 2);
    ans = (ans * ans) % mod;
    if (pow & 1) ans = (ans * x) % mod;
    return ans;
}

vector<int> g[maxn];
int sz[maxn];
bool used[maxn];
int ans_[maxn], ans1[maxn];
void dfs(int v, int p) {
    sz[v] = 1;
    ans_[v] = 1;
    used[v] = true;
    int cnt = 0;
    ll raz = 0;
    for (auto u: g[v]) {
        if (u == p) continue;
        dfs(u, v);
        sz[v] += sz[u];
        ans_[v] = (ans_[v] * mod_bin_pow(2, sz[u])) % mod;
        raz += mod_bin_pow(2, sz[u]) - 1;
        raz %= mod;
    }
    ans1[v] = mod_bin_pow(2, sz[v] - 1);
    ans_[v] -= raz + 1;
    ans_[v] += mod;
    ans_[v] %= mod;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> x(k);
    for (int i = 0; i < k; ++i) {
        cin >> x[i];
        --x[i];
    }
    for (int i = 1; i <= n - 1; ++i) {
        int p; cin >> p; --p;
        g[i].emplace_back(p), g[p].emplace_back(i);
    }
    for (int i = 0; i < n; i++) {
        if (used[i]) continue;
        dfs(i, i);
    }
    for (auto el: x) {
        ll ans = 1;
        cout << (ans1[el] + ans_[el]) % mod << " ";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
}