#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<ll> a,b,c,d,sum1,sum2;
ll binary(vector<ll> A, ll low, ll high, ll x){
ll mid, result=-1;
while(low<=high){
mid = (low+high)/2;
if(A[mid]==x && (mid-1<0 || A[mid-1]<x))
{
result = mid;
break;
}
else if((A[mid]==x && A[mid-1]==x) || (x<A[mid]))
{
high = mid-1;
}
else
{
low = mid+1;
}
//cout << " stuck " << endl;
}
return result;
}
ll binary1( vector<ll> A, ll low, ll high, ll x) {
ll mid , result =-1;
while(low<=high){
mid = (low+high)/2;
if(A[mid]==x && (mid+1==A.size() || A[mid+1]>x))
{
result = mid;
break;
}
else if((A[mid]==x && A[mid+1]==x) || (A[mid]<x))
{
low = mid+1;
}
else{
high = mid-1;
}
//cout << " stuck1 " << endl;
}
return result;
}
int main() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int t, cases=0;
cin >> t;
while(t--) {
long long n, k;
cin >> n >> k;
a.clear();
b.clear();
c.clear();
d.clear();
sum1.clear();
sum2.clear();
for(long long int i=0;i<n;i++) {
long long int x;
cin >> x;
a.push_back(x);
}
for(long long int j=0;j<n;j++) {
long long int x;
cin >> x;
b.push_back(x);
}
for(long long int i=0;i<n;i++) {
long long int x;
cin >> x;
c.push_back(x);
}
for(long long int j=0;j<n;j++) {
long long int x;
cin >> x;
d.push_back(x);
}
for(ll i=0;i<n;i++) {
for(ll j =0; j< n;j++) {
sum1.pb((ll)((a[i]^b[j])));
}
}
for(ll i=0;i<n;i++) {
for(ll j=0;j<n;j++) {
sum2.pb((ll)((c[i])^d[j]));
}
}
//sort(sum1.begin(), sum1.end());
sort(sum2.begin(), sum2.end());
ll answer=0;
cout << sum1.size() << endl;
for(ll i=0;i<sum1.size();i++) {
ll l1 = binary(sum2,0,sum2.size()-1, k^sum1[i]);
ll l2 = binary1(sum2,0, sum2.size()-1,k^sum1[i]);
if(l1!=-1 && l2!=-1){
answer += (l2-l1+1);
}
//cout << " return " << endl;
}
cout << "Case #" << ++cases << ": " << answer << endl;
}
fclose(stdout);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbGwgbG9uZyBsb25nIAojZGVmaW5lIHBiIHB1c2hfYmFjawp2ZWN0b3I8bGw+IGEsYixjLGQsc3VtMSxzdW0yOwpsbCBiaW5hcnkodmVjdG9yPGxsPiBBLCBsbCBsb3csIGxsIGhpZ2gsIGxsIHgpewogICAgbGwgbWlkLCByZXN1bHQ9LTE7CiAgICB3aGlsZShsb3c8PWhpZ2gpewogICAgICAgICBtaWQgPSAobG93K2hpZ2gpLzI7CiAgICAgICAgaWYoQVttaWRdPT14ICYmIChtaWQtMTwwIHx8IEFbbWlkLTFdPHgpKQogICAgICAgIHsKICAgICAgICAgICAgcmVzdWx0ID0gbWlkOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZigoQVttaWRdPT14ICYmIEFbbWlkLTFdPT14KSB8fCAoeDxBW21pZF0pKQogICAgICAgIHsKICAgICAgICAgICAgaGlnaCA9IG1pZC0xOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBsb3cgPSBtaWQrMTsKICAgICAgICB9CgkvL2NvdXQgPDwgIiBzdHVjayAiIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gcmVzdWx0Owp9CmxsIGJpbmFyeTEoIHZlY3RvcjxsbD4gQSwgbGwgbG93LCBsbCBoaWdoLCBsbCB4KSB7CiAgICBsbCBtaWQgLCByZXN1bHQgPS0xOwogICAgd2hpbGUobG93PD1oaWdoKXsKICAgICAgICAgbWlkID0gKGxvdytoaWdoKS8yOwogICAgICAgICBpZihBW21pZF09PXggJiYgKG1pZCsxPT1BLnNpemUoKSB8fCBBW21pZCsxXT54KSkKICAgICAgICAgewogICAgICAgICAgICAgcmVzdWx0ID0gbWlkOwogICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgIH0KICAgICAgICAgZWxzZSBpZigoQVttaWRdPT14ICYmIEFbbWlkKzFdPT14KSB8fCAoQVttaWRdPHgpKQogICAgICAgICB7CiAgICAgICAgICAgICBsb3cgPSBtaWQrMTsKICAgICAgICAgfQogICAgICAgICBlbHNlewogICAgICAgICAgICAgaGlnaCA9IG1pZC0xOwogICAgICAgICB9CgkvL2NvdXQgPDwgIiBzdHVjazEgIiA8PCBlbmRsOwogICAgfQogICAgcmV0dXJuIHJlc3VsdDsKfQoKCmludCBtYWluKCkgewoJZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwoJZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7CglpbnQgdCwgY2FzZXM9MDsKCWNpbiA+PiB0OwoJd2hpbGUodC0tKSB7CgkJbG9uZyBsb25nIG4sIGs7CgkJY2luID4+IG4gPj4gazsKCQlhLmNsZWFyKCk7CgkJYi5jbGVhcigpOwoJCWMuY2xlYXIoKTsKCQlkLmNsZWFyKCk7CgkJc3VtMS5jbGVhcigpOwoJCXN1bTIuY2xlYXIoKTsKCQlmb3IobG9uZyBsb25nIGludCBpPTA7aTxuO2krKykgewoJCQlsb25nIGxvbmcgaW50IHg7CgkJCWNpbiA+PiB4OwoJCQlhLnB1c2hfYmFjayh4KTsKCQl9CgkJZm9yKGxvbmcgbG9uZyBpbnQgaj0wO2o8bjtqKyspIHsKCQkJbG9uZyBsb25nIGludCB4OwoJCQljaW4gPj4geDsKCQkJYi5wdXNoX2JhY2soeCk7CgkJfQoJCSBmb3IobG9uZyBsb25nIGludCBpPTA7aTxuO2krKykgewogICAgICAgICAgICAgICAgICAgICAgICBsb25nIGxvbmcgaW50IHg7CiAgICAgICAgICAgICAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICAgICAgICAgICAgICBjLnB1c2hfYmFjayh4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZvcihsb25nIGxvbmcgaW50IGo9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