#include #include using namespace std; #include using mint = atcoder::modint998244353; mint solve() { int N, M; cin >> N >> M; vector X(N); for (int &x : X) cin >> x; long long fixed_sum = 0; int nempty = 0; for (int x : X) { if (x < 0) { ++nempty; } else { fixed_sum += x; } } if (nempty == 1) { long long rem = (M - fixed_sum % M) % M; for (auto &x : X) { if (x < 0) { assert(x == -1); x = rem; --nempty; fixed_sum += rem; } } } if (!nempty and fixed_sum % M) return 0; if (!nempty) { mint ret = 0; long long current_sum = 0; for (int x : X) { current_sum += x; if (current_sum % M) ret += 1; } return ret; } mint ret = 0; long long current_sum = 0; int current_empty = 0; const mint c = mint(M).pow(nempty - 2); for (int x : X) { if (x < 0) { ++current_empty; } else { current_sum += x; } if (current_empty == 0) { if (current_sum % M) ret += c * M; } else if (current_empty == nempty) { if ((fixed_sum - current_sum) % M) ret += c * M; } else { ret += c * (M - 1); } } return ret; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int T; cin >> T; while (T--) cout << solve().val() << '\n'; }