#include <bits/stdc++.h>

using namespace std;

long long MOD = 998244353;

long long binary_pow(long long x, long long y){
    if (y == 0){
        return 1;
    }

    long long tmp = binary_pow(x, y/2);

    if (y % 2 == 0){
        return tmp*tmp%MOD;
    } else {
        return tmp*tmp%MOD*x%MOD;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, q;

    cin >> n >> q;

    vector<long long> lst_els(n+1, 0);

    for (int i = 1; i <= n; ++i){
        cin >> lst_els[i];
    }
    
    vector<long long> anses((1 << 3), 0);

    for (int mask = 0; mask < (1 << 3); ++mask){
        vector<long long> new_lst = lst_els;
        vector<long long> new2 = new_lst;
        if (mask & (1 << 0)){
            for (int j = 1; j <= n; ++j){
                new2[j] = new_lst[n-j+1];
            }
            new_lst = new2;
        }

        if (mask & (1 << 1)){
            for (int j = 1; j <= n; ++j){
                new2[j] = n-new_lst[j]+1;
            }
            new_lst = new2;
        }

        if (mask & (1 << 2)){
            for (int j = 1; j <= n; ++j){
                new2[new_lst[j]] = j;
            }
            new_lst = new2;
        }

        long long curr_ans = 0;

        for (int j = 1; j <= n; ++j){
            curr_ans = (curr_ans + binary_pow(new_lst[j], j))%MOD;
        }

        anses[mask] = curr_ans;
    }

    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;

    for (int i = 0; i < q; ++i){
        int type;

        cin >> type;

        if (type == 1){
            cnt1++;
        } else if (type == 2){
            cnt2++;
        } else {
            cnt3++;
        }

        int curr_mask = 0;

        if (cnt1%2 == 1){
            curr_mask += (1 << 0);
        }
        if (cnt2%2 == 1){
            curr_mask += (1 << 1);
        }
        if (cnt3%2 == 1){
            curr_mask += (1 << 2);
        }

        cout << anses[curr_mask] << " ";
    }
}