#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18, MOD = 998244353;
mt19937 rnd(time(0));

void solve();

int mt(int a, int b){
    return (a * 1ll * b) % MOD;
}
int sm(int a, int b){
    if (a + b >= MOD){
        return a + b - MOD;
    }
    return a + b;
}
int bin_pow(int a, int n){
    if (n == 0){return 1;}
    if (n == 1){return a;}
    if (n % 2 == 0){return bin_pow(mt(a, a), n / 2);}
    else{
        return mt(a, bin_pow(a, n - 1));
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++){cin >> p[i];}
    vector<int> qq(n);
    for (int i = 0; i < n; i++){
        qq[i] = n - p[i] + 1;
    }
    int a = 0, a1 = 0;
    for (int i = 0; i < n; i++){
        a = sm(a, bin_pow(p[i], i + 1));
        a1 = sm(a1, bin_pow(qq[i], i + 1));
    }
    int c = 0;
    while (q--){
        int t;
        cin >> t;
        if (t == 1){
            c++;
        }
        else if (t == 2){
            c++;
        }
        else{

        }
        if (c % 2 == 1){cout << a1 << " ";}
        else{cout << a << " ";}
    }
}


