def pow(a, n, m):
    if n == 0:
        return 1
    if n % 2 == 0:
        l = pow(a, n / 2, m)
        return (l * l) % m
    return (pow(a, n - 1, m) * a) % m


def f(a):
    k = 0
    for i in range(len(a)):
        k += pow(a[i], i + 1, 998244353)
        k %= 998244353
    return k


def f1(a):
    ans = [0]*len(a)
    for i in range(len(a)):
        ans[i] = a[len(a) - i - 1]
    return ans


def f2(a):
    ans = [0]*len(a)
    for i in range(len(a)):
        ans[i] = len(a) - a[i] + 1
    return ans


def f3(a):
    ans = [0]*len(a)
    for i in range(len(a)):
        ans[a[i] - 1] = i + 1
    return ans


n, q = map(int, input().split())
a = list(map(int, input().split()))
v = list(map(int, input().split()))
l1 = f(a)
l2 = f(f1(a))
l3 = f(f2(a))
l4 = f(f1(f2(a)))
k1 = 0
k2 = 0
for el in v:
    if el == 1:
        k1+=1
    else:
        k2+=1
    if k1 % 2 == 0 and k2 % 2 == 0:
        print(l1)
    elif k1 % 2 == 0:
        print(l3)
    elif k2 % 2 == 0:
        print(l2)
    else:
        print(l4)
