/***********Template Starts Here***********/
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
using namespace std;
typedef long long vlong;
typedef vector<int> vi;
const vlong inf = 2147383647;
/***********Template Ends Here***********/
struct node {
int x, y, next, cap, cost;
};
#define NODE 20010
#define EDGE 5000010
///Flow Template
struct FLOW {
int source, sink;
int head[NODE];
void clear() {
e = 0;
CLR(head,-1);
}
node edge[EDGE]; int e;
void addEdge ( int u, int v, int cap ) {
edge[e].x = u; edge[e].y = v; edge[e].cap = cap;
edge[e].next = head[u]; head[u] = e; e++;
edge[e].x = v; edge[e].y = u; edge[e].cap = 0;
edge[e].next = head[v]; head[v] = e; e++;
}
int vis[NODE], q[NODE], now[NODE];
bool bfs ( ) {
memset ( vis, -1, sizeof vis );
vis[source] = 0;
int ini = 0, qend = 0;
q[qend++] = source;
while ( ini < qend && vis[sink] == -1 ) {
int s = q[ini++];
int i;
for (i=head[s];i!=-1;i= edge[i].next){
int t = edge[i].y;
if ( vis[t] == -1 && edge[i].cap){
vis[t] = vis[s] + 1;
q[qend++] = t;
}
}
}
if ( vis[sink] != -1 ) return true;
else return false;
}
int dfs ( int s, int f ) {
if ( f == 0 ) return 0;
if ( s == sink ) return f;
for ( int &i=now[s];i!=-1;i=edge[i].next){
int t = edge[i].y;
if ( vis[s] + 1 != vis[t] ) continue;
int pushed=dfs(t,MIN(f,edge[i].cap));
if ( pushed ) {
edge[i].cap -= pushed;
edge[i^1].cap += pushed;
return pushed;
}
}
return 0;
}
int maxFlow ( int limit, int flow ) {
int res = 0;
while ( 1 ) {
if ( flow == 0 ) break;
if ( bfs () == false ) break;
int i;
for ( i=0;i<=limit;i++)now[i]= head[i];
while (int pushed=dfs(source,flow ) ) {
res += pushed; ///Can overflow depending on Max Flow
flow -= pushed;
}
}
return res;
}
}graph;
int vis[10010], vv = 1;
int qqq[10010]; ///Queue for BFS
int total = 0;
///Generate all children
void bfs ( int s, int lim ) {
int qh, qt;
qh = qt = 0;
qqq[qt++] = s;
vis[s] = vv;
while ( qh < qt ) {
s = qqq[qh++];
FOR(i,0,15) {
if ( s & ( 1 << i ) ) {
int t = s + ( 1 << i ); ///Generate Child
if ( t <= lim ) {
if ( vis[t] != vv ) { ///Has not been generated before
vis[t] = vv;
qqq[qt++] = t;
}
}
}
}
}
}
int mp[10010];
int main () {
#ifdef forthright48
freopen ( "input.txt", "r", stdin );
//freopen ( "output.txt", "w", stdout );
#endif // forthright48
int kase;
scanf ( "%d", &kase );
int cnt = 0;
while ( kase-- ) {
int n;
scanf ( "%d", &n );
int l;
scanf ( "%d", &l );
graph.clear(); ///Clear Graph
vv++; ///Clear visit array
FOR(i,0,n-1) {
int seed;
scanf ( "%d", &seed );
bfs ( seed, l ); ///Generate all children of seed
}
vi child;
FOR(i,1,l) {
if ( vis[i] == vv ) child.pb ( i ); ///Collect all child in one place
}
int cur = 1;
///Map all children to new nodes. This is necessary to lower node number in Flow
FOR(i,0,SZ(child)-1) {
mp[child[i]] = cur++;
}
int node = child.size();
graph.source = 0;
graph.sink = node + node + 1; ///Assign source and sink
FOR(i,1,node) {
graph.addEdge(0,i,1); ///Add edge from source to left side
graph.addEdge(i+node,node + node + 1,1); ///Add edge from right side to sink
}
FOR(c,0,SZ(child)-1) {
int s = child[c];
FOR(i,0,15) {
if ( s & ( 1 << i ) ) {
int t = s + ( 1 << i );
if ( t <= l ) {
graph.addEdge ( c+1, node + mp[t], 1 ); ///Add edge between left and right side
}
}
}
}
int m = graph.maxFlow(node+node+1,inf); ///Find flow
printf ( "Case %d: %d\n", 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KyAxOwogICAgICAgICAgICAgICAgICAgIHFbcWVuZCsrXSA9IHQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKCB2aXNbc2lua10gIT0gLTEgKSByZXR1cm4gdHJ1ZTsKICAgICAgICBlbHNlIHJldHVybiBmYWxzZTsKICAgIH0KICAgIGludCBkZnMgKCBpbnQgcywgaW50IGYgKSB7CiAgICAgICAgaWYgKCBmID09IDAgKSByZXR1cm4gMDsKICAgICAgICBpZiAoIHMgPT0gc2luayApIHJldHVybiBmOwogICAgICAgIGZvciAoIGludCAmaT1ub3dbc107aSE9LTE7aT1lZGdlW2ldLm5leHQpewogICAgICAgICAgICBpbnQgdCA9IGVkZ2VbaV0ueTsKICAgICAgICAgICAgaWYgKCB2aXNbc10gKyAxICE9IHZpc1t0XSApIGNvbnRpbnVlOwogICAgICAgICAgICBpbnQgcHVzaGVkPWRmcyh0LE1JTihmLGVkZ2VbaV0uY2FwKSk7CiAgICAgICAgICAgIGlmICggcHVzaGVkICkgewogICAgICAgICAgICAgICAgZWRnZVtpXS5jYXAgLT0gcHVzaGVkOwogICAgICAgICAgICAgICAgZWRnZVtpXjFdLmNhcCArPSBwdXNoZWQ7CiAgICAgICAgICAgICAgICByZXR1cm4gcHVzaGVkOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgfQoKICAgIGludCBtYXhGbG93ICggaW50IGxpbWl0LCBpbnQgZmxvdyApIHsKICAgICAgICBpbnQgcmVzID0gMDsKICAgICAgICB3aGlsZSAoIDEgKSB7CiAgICAgICAgICAgIGlmICggZmxvdyA9PSAwICkgYnJlYWs7CiAgICAgICAgICAgIGlmICggYmZzICgpID09IGZhbHNlICkgYnJlYWs7CiAgICAgICAgICAgIGludCBpOwogICAgICAgICAgICBmb3IgKCBpPTA7aTw9bGltaXQ7aSsrKW5vd1tpXT0gaGVhZFtpXTsKICAgICAgICAgICAgd2hpbGUgKGludCBwdXNoZWQ9ZGZzKHNvdXJjZSxmbG93ICkgKSB7CiAgICAgICAgICAgICAgICByZXMgKz0gcHVzaGVkOyAvLy9DYW4gb3ZlcmZsb3cgZGVwZW5kaW5nIG9uIE1heCBGbG93CiAgICAgICAgICAgICAgICBmbG93IC09IHB1c2hlZDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgfQp9Z3JhcGg7CgppbnQgdmlzWzEwMDEwXSwgdnYgPSAxOwppbnQgcXFxWzEwMDEwXTsgLy8vUXVldWUgZm9yIEJGUwppbnQgdG90YWwgPSAwOwoKLy8vR2VuZXJhdGUgYWxsIGNoaWxkcmVuCnZvaWQgYmZzICggaW50IHMsIGludCBsaW0gKSB7CiAgICBpbnQgcWgsIHF0OwogICAgcWggPSBxdCA9IDA7CiAgICBxcXFbcXQrK10gPSBzOwoKICAgIHZpc1tzXSA9IHZ2OwoKICAgIHdoaWxlICggcWggPCBxdCApIHsKICAgICAgICBzID0gcXFxW3FoKytdOwoKICAgICAgICBGT1IoaSwwLDE1KSB7CiAgICAgICAgICAgIGlmICggcyAmICggMSA8PCBpICkgKSB7CiAgICAgICAgICAgICAgICBpbnQgdCA9IHMgKyAoIDEgPDwgaSApOyAvLy9HZW5lcmF0ZSBDaGlsZAogICAgICAgICAgICAgICAgaWYgKCB0IDw9IGxpbSApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoIHZpc1t0XSAhPSB2diApIHsgLy8vSGFzIG5vdCBiZWVuIGdlbmVyYXRlZCBiZWZvcmUKICAgICAgICAgICAgICAgICAgICAgICAgdmlzW3RdID0gdnY7CiAgICAgICAgICAgICAgICAgICAgICAgIHFxcVtxdCsrXSA9IHQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9CgppbnQgbXBbMTAwMTBdOwoKaW50IG1haW4gKCkgewogICAgI2lmZGVmIGZvcnRocmlnaHQ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gaW50IG5vZGUgPSBjaGlsZC5zaXplKCk7CiAgICAgICAgZ3JhcGguc291cmNlID0gMDsKICAgICAgICBncmFwaC5zaW5rID0gbm9kZSArIG5vZGUgKyAxOyAvLy9Bc3NpZ24gc291cmNlIGFuZCBzaW5rCgogICAgICAgIEZPUihpLDEsbm9kZSkgewogICAgICAgICAgICBncmFwaC5hZGRFZGdlKDAsaSwxKTsgLy8vQWRkIGVkZ2UgZnJvbSBzb3VyY2UgdG8gbGVmdCBzaWRlCiAgICAgICAgICAgIGdyYXBoLmFkZEVkZ2UoaStub2RlLG5vZGUgKyBub2RlICsgMSwxKTsgLy8vQWRkIGVkZ2UgZnJvbSByaWdodCBzaWRlIHRvIHNpbmsKICAgICAgICB9CgogICAgICAgIEZPUihjLDAsU1ooY2hpbGQpLTEpIHsKICAgICAgICAgICAgaW50IHMgPSBjaGlsZFtjXTsKICAgICAgICAgICAgRk9SKGksMCwxNSkgewogICAgICAgICAgICAgICAgaWYgKCBzICYgKCAxIDw8IGkgKSApIHsKICAgICAgICAgICAgICAgICAgICBpbnQgdCA9IHMgKyAoIDEgPDwgaSApOwogICAgICAgICAgICAgICAgICAgIGlmICggdCA8PSBsICkgewogICAgICAgICAgICAgICAgICAgICAgICBncmFwaC5hZGRFZGdlICggYysxLCBub2RlICsgbXBbdF0sIDEgKTsgLy8vQWRkIGVkZ2UgYmV0d2VlbiBsZWZ0IGFuZCByaWdodCBzaWRlCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpbnQgbSA9IGdyYXBoLm1heEZsb3cobm9kZStub2RlKzEsaW5mKTsgLy8vRmluZCBmbG93CgogICAgICAgIHByaW50ZiAoICJDYXNlICVkOiAlZFxuIiwgKytjbnQsIFNaKGNoaWxkKSAtIG0gKTsgLy8vUmVzdWx0IGlzIHRvdGFsIC0gZmxvdwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==