#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using ll = long long;
using ld = long double;
mt19937 rnd(1245);

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

const ll mod = 998244353;
const ll inf = 1e9;
const ll INF = 1e18;
const int maxn = 1e5 + 1;
const int logn = 21;
const int sq = 350;
const ld eps = 1e-8;
const ld pi = acos(-1);

ll mmod(ll x, ll mod = mod) {
    x %= mod;
    if (x < 0) x += mod;
    return x;
}

ll gcd(ll a, ll b) {
    ll res;
    while (b != 0) {
        res = a;
        a = b;
        b = res % a;
    }
    return a;
}

ll binpow(ll a, ll n, ll mod = mod) {
    ll res = 1;
    while (n != 0) {
        if (n & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

map<vector<int>, int> mp;
map<int, ll> hs;
map<int, vector<int> > s;
int timer = 1;

vector<vector<int> > g(maxn);

void rec(vector<int>& a) {
    if (mp[a] != 0) {
        return;
    }
    s[timer] = a;
    mp[a] = timer++;
    vector<int> b, c;
    for (int i = 0; i < sz(a); ++i) {
        b.push_back(a[i]);
        c.push_back(a[i]);
    }
    reverse(all(b));
    rec(b);
    g[mp[a]].push_back(mp[b]);
    reverse(all(b));
    for (int i = 0; i < sz(a); ++i) {
        b[i] = sz(a) + 1 - b[i];
    }
    rec(b);
    g[mp[a]].push_back(mp[b]);
    for (int i = 0; i < sz(a); ++i) {
        b[i] = sz(a) + 1 - b[i];
    }
    for (int i = 0; i < sz(c); ++i) {
        c[b[i] - 1] = i + 1;
    }
    rec(c);
    g[mp[a]].push_back(mp[c]);
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    rec(a);
    for (auto [b, num] : mp) {
        ll d = 0;
        for (int i = 0; i < n; ++i) {
            d += binpow(b[i], i + 1);
            d %= mod;
        }
        hs[num] = d;
    }

    int now = 1;
    while (q--) {
        int type;
        cin >> type;
        cout << hs[g[now][type - 1]] << " ";
        now = g[now][type - 1];
    }

}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }

}