#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int64_t mod = 998'244'353;
int64_t binPow(int a, int b) {
    if (b == 0) return 1;
    int64_t x = binPow(a, b / 2);
    x = (x * x) % mod;
    if (b % 2) x *= a;
    return x % mod;
}

vector <vector <int>> g;
vector <int> x;
vector <int64_t> sz;

void dfs(int v) {
    sz[v] = 1;
    for (int u : g[v]) {
        dfs(u);
        sz[v] += sz[u];
    }
}



int main()
{
    int n, k;
    cin >> n >> k;
    g.resize(n);
    x.resize(k);
    sz.resize(n);
    for (int i = 0; i < k; ++i) {
        cin >> x[i]; x[i]--;
    }
    for (int i = 1; i < n; ++i) {
        int a;
        cin >> a; a--;
        g[a].push_back(i);
    }
    dfs(0);
    for (int i = 0; i < k; ++i) {
        int64_t ans = 2 * binPow(2, sz[x[i]] - 1) - 1;
        for (int u : g[x[i]]) {
            ans -= binPow(2, sz[u]) - 1;
        }
        ans = (ans % mod + mod) % mod;
        cout << ans << " ";
    }
    return 0;
}
