#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <random>
#include <deque>
#include <queue>
#include <unordered_set>
#include <unordered_map>

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long

using namespace std;

mt19937 rnd(52);

typedef long long ll;
typedef long double ld;

const ll MAXN = 5e5 + 1;
const ll MOD = 998244353;
const ll INF = 1e12;

int logpow(int num, int deg, int mod = MOD){
    int sum = 1;
    while(deg){
        if(deg % 2 == 0){
            num *= num;
            num %= mod;
            deg /= 2;
        }
        else{
            sum *= num;
            sum %= mod;
            deg--;
        }
    }
    return sum;
}

vector<int> mirror(vector<int> arr){
    int n = arr.size() - 1;
    vector<int> newarr(n + 1);
    for(int i = 1; i <= n; i++){
        newarr[i] = arr[n - i + 1];
    }
    return newarr;
}

vector<int> rev(vector<int> arr){
    int n = arr.size() - 1;
    vector<int> newarr(n + 1);
    for(int i = 1; i <= n; i++){
        newarr[i] = n - arr[i] + 1;
    }
    return newarr;
}

vector<int> obr(vector<int> arr){
    int n = arr.size() - 1;
    vector<int> newarr(n + 1);
    for(int i = 1; i <= n; i++){
        newarr[arr[i]] = i;
    }
    return newarr;
}


void solve(){
    int n, q;
    cin >> n >> q;
    vector<int> arr(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }
    int state[2][2][2];
    for(int i = 0; i < 2; i++){
        vector<int> arr1 = arr;
        if(i) arr1 = mirror(arr1);
        for(int j = 0; j < 2; j++){
            vector<int> arr2 = arr1;
            if(j) arr2 = rev(arr2);
            for(int k = 0; k < 2; k++){
                state[i][j][k] = 0;
                vector<int> arr3 = arr2;
                if(k) arr3 = obr(arr3);
                for(int g = 1; g <= n; g++){
                    state[i][j][k] += logpow(arr3[g], g);
                    state[i][j][k] %= MOD;
                }
            }
        }
    }
    int st1 = 0, st2 = 0, st3 = 0;
    while(q--){
        int type;
        cin >> type;
        if(type == 1){
            if(!st3) st1 ^= 1;
            else st2 ^= 1;
        }
        if(type == 2){
            if(!st3) st2 ^= 1;
            else st1 ^= 1;
        }
        if(type == 3){
            st3 ^= 1;
        }
        cout << state[st1][st2][st3] << " ";
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}