#include #include #include #include #include using namespace std; struct node { int a,b,c,d; }ip[1005],sn[55],res[1005]; /*int cmp(struct node x,struct node y) { if(x.a != y.a) return x.a < y.a; else if(x.b != y.b) return x.b < y.b; else if(x.c != y.c) return x.c < y.c; else return x.d < y.d; }*/ int cmp( struct node x,struct node y) { if(x.a != y.a) return x.a < y.a ? 1:0; else if(x.b != y.b) return x.b < y.b?1: 0; else if(x.c != y.c) return x.c < y.c?1 : 0; else return x.d < y.d? 1 : 0; } int main() { int T,i,j,n,m,k; cin >> T; int cnt = 0; while(T --) { cnt ++; cin >> n >>m;//n代表ip,m代表网关 for(i=1; i<=n; i++) { scanf("%d.%d.%d.%d",&ip[i].a,&ip[i].b,&ip[i].c,&ip[i].d); } for(i=1; i<=m; i++) scanf("%d.%d.%d.%d",&sn[i].a,&sn[i].b,&sn[i].c,&sn[i].d); printf("Case #%d:\n",cnt); for(i=1; i<=m; i++) { k = 0; for(j=1; j<=n; j++) { res[k].a = ip[j].a & sn[i].a; res[k].b = ip[j].b & sn[i].b; res[k].c = ip[j].c & sn[i].c; res[k++].d = ip[j].d & sn[i].d; } /* cout << " %%%%%%%%%%%%%% " << endl; for(int p=0; p