#include #include #include #include using namespace std; typedef long long ll; typedef pair pii; #define rep(i, n) for(int i = 0; i < n; ++i) #define ri(a) scanf("%d", &a) #define rii(a, b) scanf("%d%d", &a, &b) #define riii(a, b, c) scanf("%d%d%d", &a, &b, &c) #define Ttimes int T; ri(T); for(int ks = 1; ks <= T; ++ks) const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; unsigned int a[1010]; int main() { Ttimes { int n, m; rii(n, m); rep(i, n) { unsigned int b, c, d, e; scanf("%u.%u.%u.%u", &b, &c, &d, &e); a[i] = b; a[i] = (a[i] << 8) + c; a[i] = (a[i] << 8) + d; a[i] = (a[i] << 8) + e; } printf("Case #%d:\n", ks); rep(i, m) { unsigned int b, c, d, e; scanf("%u.%u.%u.%u", &b, &c, &d, &e); int t = b; t = (t << 8) + c; t = (t << 8) + d; t = (t << 8) + e; set s; rep(j, n) s.insert(t & a[j]); printf("%d\n", (int)(s.size())); } } return 0; }