#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
int temp[MAXN];

int n, q;

void transform(vector <int>& v, int t) {
    if (t == 1) {
        for (int i = 1; i <= n; i++) {
            temp[i] = v[n + 1 - i];
        }
    } else if (t == 2) {
        for (int i = 1; i <= n; i++) {
            temp[i] = n + 1- v[i];
        }
    } else {
        for (int i = 1; i <= n; i++) {
            temp[v[i]] = i;
        }
    }

    for (int i = 1; i <= n; i++) {
        v[i] = temp[i];
    }
}

const int modulo = 998244353;

long long power(long long base, int exp) {
    if (exp == 0) return 1;
    if (exp % 2 == 0) {
        long long x = power(base, exp / 2);
        return x * x % modulo;
    }
    return base * power(base, exp - 1) % modulo;
}

int solve(vector <int>& v) {
    int ans = 0;

    for (int i = 1; i <= n; i++) {
        ans += power(v[i], i);
        if (ans >= modulo) ans -= modulo;
    }

    return ans;
}

int ans[2][2][2];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> q;
    vector <int> vv(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> vv[i];
    }

    for (int a = 0; a <= 1; a++) {
        for (int b = 0; b <= 1; b++) {
            for (int c = 0; c <= 1; c++) {
                if (a) transform(vv, 1);
                if (b) transform(vv, 2);
                if (c) transform(vv, 3);

                ans[a][b][c] = solve(vv);

                if (a) transform(vv, 1);
                if (b) transform(vv, 2);
                if (c) transform(vv, 3);
            }
        }
    }

    array <bool, 4> cnt;
    
    while (q--) {
        int t;
        cin >> t;

        cnt[t] = 1 - cnt[t];

        cout << ans[cnt[1]][cnt[2]][cnt[3]] << ' ';
    }

    return 0;

}