MOD = 998244353i64 read_line.to_i.times do puts solve() end def solve n, m = read_line.split.map(&.to_i64) x = read_line.split.map(&.to_i64) if !x.includes?(-1) ans = n sum = 0 n.times do |i| sum += x[i] sum %= m ans -= 1 if sum == 0 end return sum == 0 ? ans : 0 end ans = 0i64 comb = 1i64 sum = 0i64 i = 0 while x[i] != -1 sum += x[i] sum %= m if sum == 0 ans += 1 end i += 1 end ans += comb ans %= MOD i += 1 while i < n if x[i] == -1 comb *= m comb %= MOD ans = ans * m + comb ans %= MOD else ans += comb ans %= MOD end i += 1 end return (comb * n % MOD - ans + MOD) % MOD end