#include <bits/stdc++.h>

#define int long long
#define all(a) a.begin(), a.end()
#define pii pair <int, int>
#define fr first
#define se second
#define uwu ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int maxn = 1e5 + 5;
const int mod9 = 998244353;

int bin_pow(int a, int b){
    if (b == 0){
        return 1;
    }
    if (b & 1){
        return a * bin_pow(a, b - 1)  % mod9;
    }
    int k = bin_pow(a, b / 2);
    return k * k % mod9;
}

void solve(){
    int n, q;
    cin >> n >> q;
    vector <int> a(n), b(q);
    for (int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for (int i = 0; i < q; ++i){
        cin >> b[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i){
        cnt += bin_pow(a[i], i + 1);
        cnt %= mod9;
    }
    int cnt1 = 0;
    if (b[0] == 3){
        for (int i = 0; i < n; ++i){
            cnt1 += bin_pow(i + 1, a[i]);
            cnt1 %= mod9;
        }
    }
    else if (b[0] == 2){
        for (int i = 0; i < n; ++i){
            cnt1 += bin_pow(n - a[i] + 1, i + 1);
            cnt1 %= mod9;
        }
    }
    else{
        for (int i = 0; i < n; ++i){
            cnt1 += bin_pow(a[n - i - 1], i + 1);
            cnt1 %= mod9;
        }
    }
    for (int i = 0; i < q; ++i){
        if (i & 1){
            cout << cnt << ' ';
        }
        else{
            cout << cnt1 << ' ';
        }
    }
}

int32_t main(){

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