#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

const long long MOD = 998244353ll;

long long bpow(long long a, long long n) {
    long long cur = 1ll;
    while (n != 0) {
        if (n % 2ll == 1ll) {
            cur *= a;
            cur %= MOD;
        }
        a *= a;
        a %= MOD;
        n >>= 1ll;
    }
    return cur;
}

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

    int n, q;
    std::cin >> n >> q;
    std::vector<long long> arr(n);
    for (long long& elem : arr) {
        std::cin >> elem;
    }
    std::vector<int> que(q);
    for (int& elem : que) {
        std::cin >> elem;
    }
    std::vector<std::vector<std::vector<long long>>> cost(2, std::vector<std::vector<long long>>(2, std::vector<long long>(2, 0)));
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                std::vector<long long> cur_arr = arr;
                if (i == 1) {
                    std::reverse(cur_arr.begin(), cur_arr.end());
                }
                if (j == 1) {
                    for (int ii = 0; ii < n; ++ii) {
                        cur_arr[ii] = n - cur_arr[ii] + 1;
                    }
                }
                if (k == 1) {
                    std::vector<long long> carr = cur_arr;
                    for (int ii = 0; ii < n; ++ii) {
                        cur_arr[carr[ii] - 1] = ii + 1;
                    }
                }
                for (int ii = 0; ii < n; ++ii) {
                    cost[i][j][k] = (cost[i][j][k] + bpow(cur_arr[ii], ii + 1)) % MOD;
                }
            }
        }
    }
    int fl1 = 0;
    int fl2 = 0;
    int fl3 = 0;
    for (int qi : que) {
        if (qi == 1) {
            fl1 = 1 - fl1;
        } else if (qi == 2) {
            fl2 = 1 - fl2;
        } else {
            fl3 = 1 - fl3;
        }
        std::cout << cost[fl1][fl2][fl3] << ' ';
    }
    std::cout << '\n';
    return 0;
}