#include using namespace std; typedef long long ll; typedef unsigned long long ull; const ll infl = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const int MAXN = 3005; int n, m, k; char G[MAXN][MAXN]; int a[MAXN]; int cnt[MAXN]; int main() { #ifdef __LOCAL_WONZY__ freopen("input.txt", "r", stdin); #endif int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas) { scanf("%d %d %d", &n, &m, &k); for(int i = 0; i < n; ++i) { scanf("%s", &G[i]); a[i] = 0; for(int j = 0; j < m; ++j) { a[i] <<= 1; a[i] += G[i][j] == 'A' ? 1 : 0; } } int ed = (1 << m), res = 0; for(int i = 1; i < ed; ++i) { memset(cnt, 0, sizeof(cnt)); //if((1 << __builtin_popcount(i)) < k) continue; for(int j = 0; j < n; ++j) { cnt[a[j] & i] += 1; } long long sum = 0, remain = n; for(int j = 0; j < ed; ++j) { if(cnt[j] == 0) continue; sum += (long long) cnt[j] * (remain - cnt[j]); remain -= cnt[j]; if(sum >= k) break; } if(sum >= k) res += 1; } printf("Case #%d: %d\n", cas, res); } return 0; }