#include #include #include #include #include #include #include #include #include #include #include #include #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; #define LL long long // template end here const int SIZE = 40000; int d[SIZE][4],e[4]; int main(){ CASET{ printf("Case #%d:\n",case_n++); DRII(n,m); REP(i,n){ scanf("%d . %d . %d . %d",&d[i][0],&d[i][1],&d[i][2],&d[i][3]); } REP(i,m){ scanf("%d . %d . %d . %d",&e[0],&e[1],&e[2],&e[3]); setH; REP(j,n){ LL v=0; REP(k,4){ v<<=8; v|=e[k]&d[j][k]; } H.insert(v); } printf("%d\n",SZ(H)); } } return 0; }