#include #include #include #include #include #include #include #include using namespace std; int A[1001],B[1001],C[1001],D[1001],a[100],b[100],c[100],d[100]; set,pair > > se; int main() { //freopen("in.txt", "r", stdin); int t, n, m; int cas = 1; char pp; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { cin >> A[i] >> pp >> B[i] >> pp >> C[i] >> pp >> D[i]; } for (int i = 1; i <= m; i++) { cin >> a[i] >> pp >> b[i] >> pp >> c[i] >> pp >> d[i]; } printf("Case #%d:\n", cas++); for (int i = 1; i <= m; i++) { se.clear(); for (int j = 1; j <= n; j++) { int ma = a[i]&A[j]; int mb = b[i]&B[j]; int mc = c[i]&C[j]; int md = d[i]&D[j]; pair pa1,pa2; pa1 = make_pair(ma,mb); pa2 = make_pair(mc,md); se.insert(make_pair(pa1,pa2)); } printf("%d\n", se.size()); } } int aaa; //system("pause"); return 0; }