#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
long long mod = 998244353;
int n, q;
int pow1(int a, int b){
    long long pr = 1;
    for(int i = 0 ; i < b; i ++){
        pr *= a;
        pr = pr % mod;
    }
    return pr;
}
int fast_count(vector<int> x){
    long long sum = 0;
    for(int i = 0; i < n; i ++){
        sum += pow1(x[i], i + 1);
    }
    return sum;
}
vector<int> oper1(vector<int> x){
    vector<int> ans;
    for(int i = 0; i < n; i ++){
        ans.push_back(x[n - i - 1]);
    }
    return ans;
}
vector<int> oper2(vector<int> x){
    vector<int> ans;
    for(int i = 0; i < n; i ++){
        ans.push_back(n + 1 - x[i]);
    }
    return ans;
}
vector<int> oper3(vector<int> x){
    vector<int> ans(n);
    for(int i = 0; i < n; i ++){
        ans[x[i] - 1] = i + 1;
    }
    return ans;
}
int main(){

    //int n, q;
    cin >> n >> q;
    vector<int> p(n);
    vector<int> b(q);
    int command = 0;
    for(int i = 0; i < n; i ++){
        cin >> p[i];
    }

    vector<int> group;

    group.push_back(fast_count(oper1(p)));
    group.push_back(fast_count(oper2(p)));
    group.push_back(fast_count(oper2(oper1(p))));
    group.push_back(fast_count(p));
    int count1 = 0;
    int count2 = 0;

    //cout<< group[0];
    for(int i = 0; i < q; i ++){
        cin >> b[i];
        if(b[i] == 1){
            count1 = (count1 + 1) % 2;
        }
        if(b[i] == 2){
            count2 = (count2 + 1) % 2;
        }
        if(count1 == 1 and count2 == 1){
            cout << group[2] << "\n";
        }
        if(count1 == 0 and count2 == 1){
            cout << group[1] << "\n";
        }
        if(count1 == 1 and count2 == 0){
            cout << group[0] << "\n";
        }
        if(count1 == 0 and count2 == 0){
            cout << group[3] << "\n";
        }


    }
    //cout << n;
    return 0;
}
