#pragma G++ optimize(2) #include #define LL long long #define N 1005 #define M 10 + 1 #define Q 1024 + 5 using namespace std; inline LL read(){ LL x = 0,f = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') f = -1;c = getchar();} while (c <='9' && c >='0') {x = x * 10 + c - '0';c = getchar();} return x * f; } inline void write(LL x){ LL k = 0,lx = x;char put[40]; if (lx ==0) putchar('0'); if (lx < 0) putchar('-'),lx = -lx; while (lx) put[++k] = (lx % 10) + '0',lx /= 10; while (k) putchar( put[ k-- ] ); putchar('\n'); } int T,n,m,k,ans,ALL; int a[N],b[N],bit[M+10]; bool ok[Q]; inline int Get(){ char c = getchar(); while (c != 'A' && c != 'B') c = getchar(); return (int)(c - 'A'); } void init(){ n = read(),m = read(),k = read(); for (int i = 1; i <= n; ++i){ a[i] = 0; for (int j = 1; j <= m; ++j) a[i] += bit[j] * Get(); } } int ttt,g; int sum[Q]; bool check(int S){ ttt = n * (n - 1) / 2; memset(sum,0,sizeof(sum)); for (int i = 1; i <= n; ++i) ++sum[ a[i] & S ]; for (int i = 0; i <= ALL; ++i){ g = sum[i]; ttt -= g * (g-1) / 2; } return ttt >= k; } void solve(){ ans = 0; ALL = bit[m+1] - 1; memset(ok,0,sizeof(ok)); for (int i = 1; i <= ALL; ++i){ if (check(i)) { ok[i] = 1; ++ans; } } } int main(){ bit[1] = 1; for (int i = 2; i <= 15; ++i) bit[i] = bit[i-1] << 1; T = read(); for (int t = 1; t <= T; ++t){ init(); solve(); printf("Case #%d: %d\n",t,ans); } return 0; }