import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes") no = lambda :print("no");No = lambda :print("No") ####################################################################### mod = 998244353 for _ in range(ni()): n, m = na() x = na() dpc = [1, 0] dps = [0, 0] s = 0 ans = 0 for i in range(n): ndps = [0, 0] if x[i] != -1: s += x[i] s %= m if s == 0 and x[i] == 0: pass elif s == x[i]: ndps[0] = dps[0] ndps[1] = dpc[1] + dpc[1] ndps[1] %= mod else: ndps[0] = dpc[0] + dps[0] ndps[1] = dpc[1] + dps[1] ndps[0] %= mod ndps[1] %= mod else: if s == 0: ndps[0] = dpc[1] * (m-1) + dps[0] + dps[1] * (m-1) ndps[1] = dpc[1] * (m-1) + dps[0] + dps[1] * (m-1) else: ndps[0] = dpc[0] + dpc[1] * (m-2) + dps[0] + dps[1] * (m-1) ndps[1] = dpc[0] + dpc[1] * (m-2) + dps[0] + dps[1] * (m-1) ndps[0] %= mod ndps[1] %= mod dpc = [dpc[0] + dpc[1] * (m-1), dpc[0] + dpc[1] * (m-1)] dpc[0] %= mod dpc[1] %= mod dps = ndps if s == 0: print(dps[0]) else: print(dps[1])