#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <map>
#include <random>
#include <ctime>
#include <algorithm>
#include <ctime>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <numeric>
#include <deque>

using namespace std;
using ll = long long;

ll mod = 998244353;

struct mll {
    ll val;
};

mll operator+ (mll a, mll b) {
    if (a.val+b.val > mod) return {a.val+b.val-mod};
    return {a.val+b.val};
}

mll operator- (mll a, mll b) {
    if (a.val-b.val < 0) return {a.val-b.val+mod};
    return {a.val-b.val};
}

mll operator* (mll a, mll b) {
    return {(a.val*b.val)%mod};
}

mll bin_up(mll a, ll b) {
    if (b == 1) {
        return a;
    }
    if (b == 0) {
        return {1};
    }
    if (b%2 == 1) {
        mll x = bin_up(a, b/2);
        return x*x*a;
    } else {
        mll x = bin_up(a, b/2);
        return x*x;
    }
}

int main() {
    ll n, q;
    cin >> n >> q;
    vector <mll> mas(n);
    for (int i = 0; i < n; ++i) {
        ll a; cin >> a;
        mas[i].val = a;
    }
    mll ans1 = {0};
    mll ans2 = {0};
    mll ans3 = {0};
    mll ans4 = {0};
    for (int i = 0; i < n; ++i) {
        ans1 = ans1 + bin_up(mas[i], i+1);
        ans2 = ans2 + bin_up(mas[n-i-1], i+1);
        ans3 = ans3 + bin_up({n+1-mas[i].val}, i+1);
        ans4 = ans4 + bin_up({n+1-mas[n-i-1].val}, i+1);
    }
    mll ans5 = {0};
    mll ans6 = {0};
    mll ans7 = {0};
    mll ans8 = {0};
    for (int i = 0; i < n; ++i) {
        mas[mas[i].val-1].val = i+1;
    }
    for (int i = 0; i < n; ++i) {
        ans5 = ans5 + bin_up(mas[i], i+1);
        ans6 = ans6 + bin_up(mas[n-i-1], i+1);
        ans7 = ans7 + bin_up({n+1-mas[i].val}, i+1);
        ans8 = ans8 + bin_up({n+1-mas[n-i-1].val}, i+1);
    }
    int it = 1;
    for (int z = 0; z < q; ++z) {
        int t;
        cin >> t;
        if (t == 1) {
            if (it == 1) it = 2;
            else if (it == 2) it = 1;
            else if (it == 3) it = 4;
            else if (it == 4) it = 3;
            else if (it == 5) it = 6;
            else if (it == 6) it = 5;
            else if (it == 7) it = 8;
            else if (it == 8) it = 7;
        } else if (t == 2) {
            if (it == 1) it = 3;
            else if (it == 2) it = 4;
            else if (it == 3) it = 1;
            else if (it == 4) it = 2;
            else if (it == 5) it = 7;
            else if (it == 6) it = 8;
            else if (it == 7) it = 5;
            else if (it == 8) it = 6;
        } else if (t == 3) {
            if (it == 1) it = 5;
            else if (it == 2) it = 6;
            else if (it == 3) it = 7;
            else if (it == 4) it = 8;
            else if (it == 5) it = 1;
            else if (it == 6) it = 2;
            else if (it == 7) it = 3;
            else if (it == 8) it = 4;
        }
        if (it == 1) {
            cout << ans1.val << ' ';
        } else if (it == 2) {
            cout << ans2.val << ' ';
        } else if (it == 3) {
            cout << ans3.val << ' ';
        } else if (it == 4) {
            cout << ans4.val << ' ';
        } else if (it == 5) {
            cout << ans5.val << ' ';
        } else if (it == 6) {
            cout << ans6.val << ' ';
        } else if (it == 7) {
            cout << ans7.val << ' ';
        } else if (it == 8) {
            cout << ans8.val << ' ';
        }
    }
}