#include <bits/stdc++.h>

using namespace std;

#define int long long
const int MN = -1e8, MX = 1e8, MOD = 998244353;

int pov(int n, int a){
    if(a == 0)
        return 1;
    if(a == 1)
        return n % MOD;
    int x = pov(n, a / 2);
    if(a % 2)
        return ((x * x % MOD) * n) % MOD;
    return (x * x % MOD);
}

signed main(){
    int n, q;
    cin >> n >> q;
    int x = 0, y1 = 0, y2 = 0, y3 = 0;
    vector<int> p(n);
    for(int i = 0; i < n; ++i)
        cin >> p[i];
    for(int i = 0; i < n; ++i)
        x += pov(p[i], i + 1);
    for(int i = 0; i < n; ++i)
        y1 = (y1 + pov(p[n - i - 1], i + 1)) % MOD;
    for(int i = 0; i < n; ++i)
        y2 = (y2 + pov(n - p[i] + 1, i + 1)) % MOD;
    for(int i = 0; i < n; ++i)
        y3 = (y3 + pov(i + 1, p[i])) % MOD;
    int b1 = 0, b2 = 0, b3 = 0;
    for(int i = 0; i < q; ++i){
        int b;
        cin >> b;
        if(b == 1){
            b1 = (b1 + 1) % 2;
            if(b1 == 0)
                cout << x << ' ';
            else
                cout << y1 << ' ';
        }
        if(b == 2){
            b2 = (b2 + 1) % 2;
            if(b2 == 0)
                cout << x << ' ';
            else
                cout << y2 << ' ';
        }
        if(b == 3){
            b3 = (b3 + 1) % 2;
            if(b3 == 0)
                cout << x << ' ';
            else
                cout << y3 << ' ';
        }
    }
}










