#include <iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;
const int mod = 998244353;
const int N = 1e5, K= 20;
vector<vector<int>> arr(N, vector<int>(K));
void build(int n, vector<int> a){
    for (int i =0;i< n; i++) {
        arr[i][0] = i+1;
        for (int j =1; j< K; j++) {
            arr[i][j] = (arr[i][j-1]*arr[i][j-1])%mod;
        }
    }
}
int f(int a, int b) {
    int ans = 1;
    for (int i = K-1; i>=0; i--) {
        if (b>=(1<<i)) {
            b-=(1<<i);
            ans = (ans*arr[a-1][i])%mod;
        }
    }
    return ans%mod;
}
void f1(int t, vector<int>& a, vector<int>&b) {
    int n = a.size();
    for (int i =0;i< n; i++) {
        if (t==1){b[i] = n-b[i]+1;}
        if (t==2){a[i] = n-a[i]+1;}
        if (t==3){swap(a[i], b[i]);}
    }
}
signed main() {
    int n, q;
    cin>> n >> q;
    vector<int> a(n);
    vector<int> b(n);
    for (int i =0;i< n; i++) {
        cin>> a[i];b[i]=i+1;
    }
    build(n, a);
    vector<int> dp(8), aa, bb;
    vector<vector<int>> g = arr;
    for (int i =0;i< 8; i++) {
        aa= a;bb=b;
        if (i&1){f1(1, aa, bb);}
        if (i&2){f1(2, aa, bb);}
        if (i&4){f1(3, aa, bb);}
        for (int j = 0;j<n; j++) {
            dp[i] = (dp[i]+f(aa[j], bb[j]))%mod;
        }
    }
    int fl1 = 0, fl2 = 0, fl3 = 0;
    while (q--) {
        int t;
        cin>> t;
        if (t==1) {
            if (!fl3){fl1 = !fl1;}
            else{fl2=!fl2;}
        }
        if (t==2){
            if (fl3){fl1 = !fl1;}
            else{fl2=!fl2;}
        }
        if (t==3){fl3=!fl3;}
        cout << dp[fl1+fl2*2+fl3*4]<<endl;
    }
    return 0;
}