#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;
    }
    long long cost_first = 0;
    for (int i = 0; i < n; ++i) {
        cost_first = (cost_first + bpow(arr[i], i + 1)) % MOD;
    }
    std::reverse(arr.begin(), arr.end());
    long long cost_second = 0;
    for (int i = 0; i < n; ++i) {
        cost_second = (cost_second + bpow(arr[i], i + 1)) % MOD;
    }
    std::reverse(arr.begin(), arr.end());
    bool is_rev = false;
    for (int i = 0; i < q; ++i) {
        if (que[i] == 1 || que[i] == 2) {
            is_rev = !is_rev;
        } else {
            is_rev = false;
        }
        if (is_rev) {
            std::cout << cost_second << ' ';
        } else {
            std::cout << cost_first << ' ';
        }
    }
    std::cout << '\n';
    return 0;
}