#include <bits/stdc++.h>

using namespace std;

mt19937_64 rd(52);
const long long mod = 998244353;
map<long long, long long> mp;

long long step(long long a, long long st){
    if(st == 0){
        return 1;
    }
    if(st == 1){
        return a % mod;
    }
    long long hl = step(a, st / 2);
    hl *= hl;
    hl %= mod;
    if(st % 2){
        hl *= a;
        hl %= mod;
    }
    return hl;
}

int main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long n, q;
    cin >> n >> q;
    vector<long long> v(n);
    for(long long i = 0; i < n; i++){
        cin >> v[i];
    }
    for(long long mask = 0; mask < 8; mask++){
        vector<long long> nv = v;
        if(mask & 1){
            reverse(nv.begin(), nv.end());
        }
        if(mask & 2){
            for(long long i = 0; i < n; i++){
                nv[i] = n + 1 - nv[i];
            }
        }
        if(mask & 4){
            vector<long long> nnv(n);
            for(long long i = 0; i < n; i++){
                nnv[nv[i] - 1] = i + 1;
            }
            nv = nnv;
        }
        long long cnt = 0;
        for(long long i = 0; i < n; i++){
            cnt += step(nv[i], i + 1);
            cnt %= mod;
        }
        mp[mask] = cnt;
    }
    long long noww = 0;
    for(long long i = 0; i < q; i++){
        long long ch;
        cin >> ch;
        ch--;
        noww ^= (1 << ch);
        cout << mp[noww] << " ";
    }
}
