#include #include using namespace std; struct rec { int a, b, c, d; bool operator <(const rec &s) const { if (this->a == s.a && this->b == s.b && this->c == s.c) return this->d < s.d; else if (this->a == s.a && this->b == s.b) return this->c < s.c; else if (this->a == s.a) return this->b < s.b; else return this->a < s.a; } }; set s; const int MAXN = 1000; const int MAXM = 50; rec ip[MAXN]; rec sm[MAXM]; int main() { int t; scanf("%d", &t); for (int i = 1; i <= t; i++) { printf("Case #%d:\n", i); int n, m; scanf("%d%d", &n, &m); for (int j = 0; j < n; j++) { scanf("%d.%d.%d.%d", &ip[j].a, &ip[j].b, &ip[j].c, &ip[j].d); } for (int j = 0; j < m; j++) { scanf("%d.%d.%d.%d", &sm[j].a, &sm[j].b, &sm[j].c, &sm[j].d); } for (int j = 0; j < m; j++) { for (int k = 0; k < n; k++) { rec tmp; tmp.a = sm[j].a & ip[k].a; tmp.b = sm[j].b & ip[k].b; tmp.c = sm[j].c & ip[k].c; tmp.d = sm[j].d & ip[k].d; s.insert(tmp); } printf("%lu\n", s.size()); s.clear(); } } return 0; }