#pragma GCC optimize("Ofast")
#pragma GCC target("avx2", "bmi2", "popcnt", "lzcnt")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <climits>
#include <queue>
#include <random>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <vector>
#include <string>

using namespace std;
using namespace __gnu_pbds;

typedef long long int lint;
typedef long double ld;
typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ost;

constexpr int MOD = (int) 998'244'353;

lint binpow(lint a, lint c) {
    lint res = 1;
    for (;c; c >>= 1) {
        if (c & 1) res = res * a % MOD;
        a = a * a % MOD;
    }
    return res;
}

inline void preset() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
}

int n;

lint f(vector <int> &p) {
    lint cost = 0;
    for (int i = 0; i < n; ++i) {
        cost += binpow(p[i] + 1, i + 1);
    }
    return cost % MOD;
}

int main() {
    preset();
    int q;
    cin >> n >> q;
    vector<int> p(n);
    for (auto &el: p) {
        cin >> el;
        --el;
    }
    const lint c0 = f(p);
    lint c1, c2, c3;
    {
        reverse(p.begin(), p.end());
        c1 = f(p);
        reverse(p.begin(), p.end());
        for (int i = 0; i < n; ++i) p[i] = n - 1 - p[i];
        c2 = f(p);
        for (int i = 0; i < n; ++i) p[i] = n - 1 - p[i];
        vector <int> qp(n);
        for (int i = 0; i < n; ++i) qp[p[i]] = i;
        c3 = f(qp);
    }
    bool rev = false;
    for (int qi = 0; qi < q; ++qi) {
        int cmd; cin >> cmd;
        if (cmd == 1) {
            // reverse
            // cout << c1 << "\n";
            rev ^= 1;
        }
        else if (cmd == 2) {
            // cout << c2 << "\n";
            rev ^= 1;
        }
        else {
            // cout << c3 << "\n";
        }
        cout << (rev ? c1 : c0) << " ";
    }
    return 0;
}
