#include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; int N; ll M; int X[201010]; ll Sf[201010], Sb[201010]; mint mpow(mint a, ll b){ if(b == 0)return 1; mint r = 1; while(b){ if(b & 1)r = r * a; a = a * a; b >>= 1; } return r; } void solve(){ cin >> N >> M; int c = 0; Sf[0] = Sb[N - 1] = 0; for(int i = 0;i < N;i++){ cin >> X[i]; c += (X[i] == -1); } for(int i = 0;i < N;i++){ Sf[i] += X[i]; Sf[i + 1] = Sf[i]; } for(int i = N - 1;i > 0;i--){ Sb[i - 1] = X[i] + Sb[i]; } if(c == 0){ int ans = N; for(int i = 0;i < N;i++){ ans -= (Sf[i] % M) == 0; } cout << (Sf[N - 1] % M == 0 ? ans : 0) << "\n"; return; } if(c == 1){ ll s = 0; ll k = (M - (Sf[N - 1] + 1) % M) % M; int ans = N; for(int i = 0;i < N;i++){ s += (X[i] == -1 ? k : X[i]); s %= M; ans -= (s == 0); } cout << ans << "\n"; return; } mint ans = mpow(M, c - 1) * N; int nc = 0; for(int i = 0;i < N;i++){ if(X[i] == -1){ nc++; c--; } mint f = (nc == 0 ? Sf[i] % M == 0 : mpow(M, nc - 1)); mint g = ( c == 0 ? Sb[i] % M == 0 : mpow(M, c - 1)); ans -= f * g; } cout << ans.val() << "\n"; } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--)solve(); return 0; }