#include #include #include using namespace std; const int MAX = 1 << 13; int solve() { int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; A[i] %= K; } vector first_sofar(K, N + 1); vector> first(N, vector(K)); for (int i = N - 1; i >= 0; --i) { int d = 0; for (int j = i; j < N; ++j) { d = (d + A[j]) % K; first_sofar[d] = min(first_sofar[d], j + 1); } first[i] = first_sofar; } vector dist(MAX, N + 1); vector visit(MAX); dist[0] = 0; for (;;) { int x = -1; for (int j = 0; j < MAX; ++j) { if (!visit[j] && dist[j] < N && (x == -1 || dist[x] > dist[j])) { x = j; } } if (x == -1) { break; } visit[x] = 1; for (int d = 0; d < K; d++) { dist[x ^ d] = min(dist[x ^ d], first[dist[x]][d]); } } int res = 0; for (int i = 0; i < MAX; ++i) { res += (dist[i] != N + 1); } return res; } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { cout << "Case #" << t << ": " << solve() << endl; } return 0; }