#include #include #include #include #include #include using namespace std; vector parse_ip(const string &s) { stringstream ss(s); vector res(4); char dot; ss >> res[0]; for(int i = 1; i < 4; i++){ ss >> dot; ss >> res[i]; } return res; } uint32_t to_net(const vector &ip, const vector &mask) { uint32_t res = 0; for(int i = 0; i < 4; i++){ uint32_t x = ip[i] & mask[i]; res = res | (x << i*8); } return res; } int main(int argc, char **argv) { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0), cout.precision(15); //1 50 int T; cin >> T; for(int cas = 1; cas <= T; cas ++){ cout << "Case #" << cas << ":\n"; //N 1 1e3 M 1 50 int N, M; cin >> N >> M; vector > ips; for(int i = 0; i < N; i++){ string s; cin >> s; //duplicate? ips.push_back(parse_ip(s)); } for(int i = 0; i < M; i++){ string s; cin >> s; vector mask = parse_ip(s); set nets; for(int j = 0; j < N; j ++){ nets.insert(to_net(ips[j], mask)); } cout << nets.size() << endl; } } return 0; }