MOD = 998244353

def apply(b, v):
    n = len(v)
    v_ = [0]*n
    for i in range(n):
        v_[i] = v[i]
    if (b == 1):
        v = v[::-1]
    elif (b == 2):
        for i in range(n):
            v[i] = n - v_[i] + 1
    else:
        for i in range(n):
            v[v_[i] - 1] = i + 1
    #print(*v)
    return v


def cost(v):
    n = len(v)
    ans = 0
    for i in range(n):
        ans += (pow(v[i], i + 1, MOD))
        #print(v[i], i + 1, ans)
    return ans % MOD

n, q = map(int, input().split())
v = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += pow(v[i], i + 1, MOD)
    ans2 += pow(v[i], n - i, MOD)
    ans1 %= MOD
    ans2 %= MOD
for b in B:
    if b == 3:
        print(ans1, end=' ')
    else:
        print(ans2, end=' ')
        ans1, ans2 = ans2, ans1

