#pragma gcc optimize("Ofast")
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <random>
#include <bitset>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
#define int long long
using ll = long long;
using ld = long double;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif

int n;
void scr(vector<int> &a) {
    vector<int> nx(n);
    for (int j = 0; j < n; j++) {
        nx[a[j] - 1] = j + 1;
    }
    a = nx;
}

void rev(vector<int> &a) {
    reverse(a.begin(), a.end());
}

void flip(vector<int> &a) {
    for (int &el : a) {
        el = n + 1 - el;
    }
}

const int MOD = 998244353;

int sum(int a, int b) {
    if (a + b < MOD) return a + b;
    return a + b - MOD;
}

int mult(int a, int b) {
    return (a * b) % MOD;
}

int binpow(int a, int st) {
    if (st == 0) return 1;
    if (st == 1) return a;
    int k = binpow(a, st / 2);
    int ost = 1;
    if (st % 2) ost = a;
    return mult(mult(k, k), ost);
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dbg(a);
    vector<vector<int>> dp(2, vector<int> (4));
    for (int scr1 = 0; scr1 < 2; scr1++) {
        for (int big = 0; big < 4; big++) {
            vector<int> temp = a;
            if (scr1) scr(temp);
            if (big % 2) flip(temp);
            if (big / 2) rev(temp);
            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans = sum(ans, binpow(temp[i], i + 1));
            }
            dp[scr1][big] = ans;
        }
    }
    vector<int> cnt(2);
    int isscr = 0;
    for (int iter = 0; iter < q; iter++) {
        int type;
        cin >> type;
        type--;
        if (type < 2) {
            cnt[type] ^= 1;
        } else {
            isscr ^= 1;
            reverse(cnt.begin(), cnt.end());
        }
        cout << dp[isscr][cnt[0] * 2 + cnt[1]] << ' ';
    }
}