#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,avx,bmi")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// using ordered_set  = tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

struct node {
    int val = INT_MAX, id;
};

struct segtree {
    vector<node> t;

    node merge(node a, node b) {
        node c;
        if (a.val < b.val) c = a;
        else c = b;
        return c;
    }

    void upd(int v, int tl, int tr, int pos, int x) {
        if (tl + 1 == tr) {
            t[v].val = x;
            t[v].id = tl;
            return;
        }
        if (pos < (tl + tr) / 2) {
            upd(v * 2, tl, (tl + tr) / 2, pos, x);
        } else {
            upd(v * 2 + 1, (tl + tr) / 2, tr, pos, x);
        }
        t[v] = merge(t[v * 2], t[v * 2 + 1]);
    }

    node get(int v, int tl, int tr, int ql, int qr) {
        if (qr <= tl || tr <= ql) return node();
        if (ql <= tl && tr <= qr) return t[v];
        return merge(get(v * 2, tl, (tl + tr) / 2, ql, qr), get(v * 2 + 1, (tl + tr) / 2, tr, ql, qr));
    }
};

int bpow(int a, int b, int mod) {
    if (!b) return 1;
    int x=bpow(a,b/2,mod);
    x=(x*x)%mod;
    if (b&1) x=(x*a)%mod;
    return x;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //cout<<3;
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int m1 = 998244353;

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

    vector<vector<int>>ans(4, {0, 0});
    {
        int cu = 0;
        for(int i=1;i<=n;++i) {
            cu+= bpow(p[i],i,m1);
            cu%=m1;
        }
        ans[1][0]=cu;
        reverse(p.begin()+1,p.end());
        for(int i=1;i<=n;++i) {
            cu+= bpow(p[i],i,m1);
            cu%=m1;
        }
        ans[1][1]=cu;
        reverse(p.begin()+1,p.end());
    }
    {
        int cu = 0;
        for(int i=1;i<=n;++i) {
            cu+= bpow(p[i],i,m1);
            cu%=m1;
        }
        ans[2][0]=cu;
        for(int i=1;i<=n;++i) {
            p[i]=(n-p[i]+1);
        }
        for(int i=1;i<=n;++i) {
            cu+= bpow(p[i],i,m1);
            cu%=m1;
        }
        ans[2][1]=cu;
        for(int i=1;i<=n;++i) {
            p[i]=(n-p[i]+1);
        }
    }
    {
        int cu = 0;
        for(int i=1;i<=n;++i) {
            cu+= bpow(p[i],i,m1);
            cu%=m1;
        }
        ans[3][0]=cu;
        vector<int>ne(n+1);
        for(int i=1;i<=n;++i) {
            ne[p[i]]=i;
        }
        for(int i=1;i<=n;++i) {
            cu+= bpow(ne[i],i,m1);
            cu%=m1;
        }
        ans[3][1]=cu;
    }
    int c = 0;
    for(int i=1;i<=q;++i) {
        int type;
        cin>>type;
        cout<<ans[type][c]<<' ';
        c^=1;
    }
}



