#include <bits/stdc++.h>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long

const int MOD = 998244353;

int fast_pow(int a, int b) {
    if (b == 0) return 1 % MOD;
    if (b == 1) return a % MOD;
    int k = fast_pow(a, b / 2) % MOD;
    return k * k % MOD * fast_pow(a, b % 2) % MOD;
}

int answer(vector<int> nums) {
    int output = 0;
    for (int i = 0; i < nums.size(); i++) {
        output = (output + fast_pow(nums[i], i + 1)) % MOD;
    }
    return output;
}

signed main() {
    int n, q;
    cin >> n >> q;
    vector<int> nums(n, 0);
    for (int i = 0; i < n; i++) cin >> nums[i];

    int a = answer(nums);

    reverse(nums.begin(), nums.end());
    int b = answer(nums);

    reverse(nums.begin(), nums.end());
    for (int i = 0; i < n; i++) {
        nums[i] = n - nums[i] + 1;
    }
    int c = answer(nums);

    reverse(nums.begin(), nums.end());
    int d = answer(nums);

    reverse(nums.begin(), nums.end());
    for (int i = 0; i < n; i++) {
        nums[i] = n - nums[i] + 1;
    }

    char status = 'a';
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            if (status == 'a') status = 'b';
            else if (status == 'b') status = 'a';
            else if (status == 'c') status = 'd';
            else if (status == 'd') status = 'c';
        } else if (t == 2) {
            if (status == 'a') status = 'c';
            else if (status == 'c') status = 'a';
            else if (status == 'b') status = 'd';
            else if (status == 'd') status = 'b';
        }
        if (status == 'a') cout << a;
        else if (status == 'b') cout << b;
        else if (status == 'c') cout << c;
        else if (status == 'd') cout << d;
        cout << '\n';
    }
}
