#include #include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define N 1020 #define M 2020 #define eps 1e-10 #define inf 1e10 #define Pi acos(-1.0) #pragma comment(linker, "/STACK:1024000000,1024000000") struct node{ int a, b, c, d; node(int a = 0, int b = 0, int c = 0, int d = 0) : a(a), b(b), c(c), d(d) {} }p[N]; int main(){ int cas, kk = 0; scanf("%d", &cas); while(cas--){ int n, m; scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) scanf("%d.%d.%d.%d", &p[i].a, &p[i].b, &p[i].c, &p[i].d); printf("Case #%d:\n", ++kk); while(m--){ map mp; int A, B, C, D, ans = 0; scanf("%d.%d.%d.%d", &A, &B, &C, &D); for(int i = 0; i < n; ++i){ node tmp = node((A & p[i].a), (B & p[i].b), (C & p[i].c), (D & p[i].d)); LL val = tmp.a * 1000000000 + tmp.b * 1000000 + tmp.c * 1000 + tmp.d; if(mp.count(val) != 0) continue; mp[val]++, ans++; } printf("%d\n", ans); } } return 0; }