    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    int mod = 998244353;
    #define o_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>
    using namespace std;
    #define int long long
    long long bin_pow(long long x, int pow) {
        if (pow == 0)return 1;
        if (pow % 2 == 1)return (x * bin_pow(x, pow - 1)) % mod;
        else {
            return bin_pow((x * x)  % mod, pow / 2) % mod;
        }
    }
    signed main() {
        int n, q;
        cin >> n >> q;
        vector<int>a(n);
        for (int i = 0;i < n;i++) {
            cin >> a[i];
        }
        vector<int>an(4 + 1);
        /*5 5
    1 2 3 4 5
    3 1 3 2 2
         */
        int colop = 0;
        for (int i = 1;i < 4;i++) {
            if (i == 3) {
                cout<<"";
            }
            vector<int>b;
            b = a;
            if (i % 2 == 1) {
                reverse(b.begin(), b.end());
            }
            if (i > 1) {
                vector<int>c(n);
                for (int j= 0;j <n;j++)c[j] = n - b[j] + 1;
                swap(c, b);
            }
            for (int j = 0;j < n;j++) {
                an[i]+=bin_pow(b[j], j + 1);
                an[i] %= mod;
            }
        }
        int col1 = 0;
        int col2 = 0;
        for (int i = 0;i < q;i++) {
            int type;
            cin >> type;
            col1 += (type == 1);
            col2 += (type == 2);
            col1 %= 2;
            col2 %= 2;
            cout << an[col1 + 2 * col2] << " ";
        }
    }