def solve(): N, M = map(int, input().split()) A = list(map(int, input().split())) Mod = 998244353 K = A.count(-1) if K == 1: i = A.index(-1) A[i] = (- sum(A[j] for j in range(N) if i != j)) % M if -1 not in A: if sum(A) % M != 0: return 0 cum = 0 k = 0 for a in A: cum += a; cum %= M if cum == 0: k += 1 return N - k left = min(i for i in range(N) if A[i] == -1) right = max (i for i in range(N) if A[i] == -1) cum = 0 H = (M - sum(A[i] for i in range(N) if A[i] != -1 and not(left < i < right))) % M S = 0 for i in range(N): if i < left: cum += A[i]; cum %= M if cum == 0: S += pow(M, K-1, Mod) elif left <= i < right: S += pow(M, K-2, Mod) else: if i == right: cum += H else: cum += A[i] cum %= M if cum == 0: S += pow(M, K-1, Mod) return (N * pow(M, K-1, Mod) - S) % Mod #================================================== import sys input=sys.stdin.readline write=sys.stdout.write T=int(input()) write("\n".join(map(str, [solve() for _ in range(T)])))