#include #include #include using namespace std; const int MAXN = 1005; const int MAXM = 55; set > book; int main() { int T, n, m; scanf("%d", &T); for (int t = 1; t <= T; t++) { vector ad[MAXN], son[MAXM]; int a, b, c, d; int res[MAXM] = { 0 }; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d.%d.%d.%d", &a, &b, &c, &d); ad[i].push_back(a); ad[i].push_back(b); ad[i].push_back(c); ad[i].push_back(d); } for (int i = 0; i < m; i++) { scanf("%d.%d.%d.%d", &a, &b, &c, &d); son[i].push_back(a); son[i].push_back(b); son[i].push_back(c); son[i].push_back(d); } for (int i = 0; i < m; i++) { book.clear(); for (int j = 0; j < n; j++) { vector temp; for (int k = 0; k < 4; k++) temp.push_back(son[i][k] & ad[j][k]); // for (auto c : temp) // printf("%d.", c); // printf("\n"); if (book.count(temp) == 0) { res[i]++; book.insert(temp); } } //printf("\n"); } printf("Case #%d:\n", t); for (int i = 0; i < m; i++) printf("%d\n", res[i]); } }