#include #include #include #include #include #include #include #include #include #include #define ms0(a) memset(a,0,sizeof(a)) #define ms1(a) memset(a,-1,sizeof(a)) #define pb(a) push_back(a) using namespace std; //typedef __int64 ll; //const double Eps = (double)1e-8; const int M = 10007; const int N = 1e5+5; //int t1[10],t2[10] struct S{ int a,b,c,d; S(int a,int b,int c,int d):a(a),b(b),c(c),d(d){} }; vector v1,v2; int main() { int t; int tt =0 ; cin>>t; while(t--) { int m,n,a,b,c,d; cin>>m>>n; v1.clear(); for(int i=0; i< m; i++) { scanf("%d.%d.%d.%d",&a,&b,&c,&d); v1.pb(S(a,b,c,d)); } printf("Case #%d:\n",++tt); for(int i=0; i< n; i++) { v2.clear(); scanf("%d.%d.%d.%d",&a,&b,&c,&d); for(int j = 0 ;j < m; j++) { int aa = a&v1[j].a; int bb = b&v1[j].b; int cc = c&v1[j].c; int dd = d&v1[j].d; int k; for(k=0; k