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 last = n.times.select { |i| x[i] == -1 }.to_a.last 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 while i < last if x[i] == -1 ans = ans * m + comb ans %= MOD comb *= m comb %= MOD else ans += comb ans %= MOD end i += 1 end sum = 0 (n - 1).downto(last + 1) do |i| sum += x[i] sum %= m if sum == 0 ans += comb end end ans %= MOD return (comb * (n - 1) % MOD - ans + MOD) % MOD end