// Created by rost on 05.03.2026.

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int MOD = 998244353;

int add(int a, int b) { return (a + b >= MOD ? a + b - MOD : a + b); }
int sub(int a, int b) { return (a - b < 0 ? a - b + MOD : a - b); }
int mult(int a, int b) { return (1ll * a * b) % MOD; }
int binp(int a, ll n) {
  int res = 1;
  while (n) {
    if (n & 1) res = mult(res, a);

    a = mult(a, a);
    n /= 2;
  }
  return res;
}

void solve() {
  int n, q;
  cin >> n >> q;
  vector<int> p(n);
  for (auto &e : p) cin >> e;

  int res[8];
  for (int state = 0; state < 8; ++state) {
    bool reverse = (state >> 0) & 1;
    bool rVal = (state >> 1) & 1;
    bool mode = (state >> 2) & 1;

    res[state] = 0;
    for (int i = 0; i < n; ++i) {
      if (!mode) {
        res[state] = add(res[state], binp((rVal ? n - p[i] + 1 : p[i]), (reverse ? n - i : i + 1)));
      } else {
        res[state] = add(res[state], binp((reverse ? n - i : i + 1), (rVal ? n - p[i] + 1 : p[i])));
      }
    }
  }

  int state = 0;
  for (int i = 0; i < q; ++i) {
    int x;
    cin >> x;
    --x;

    state ^= (1 << x);
    cout << res[state] << ' ';
  }
  cout << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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