#include <bits/stdc++.h>
using namespace std;
bool f(int i,int j){return i>j;}
int main()
{
int t,d;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>d;
vector<int> v(d);
for(int j=0;j<d;j++)cin>>v[j];
sort(v.begin(),v.end(),f);
if(v[0]==1)cout<<"Case #"<<i<<": "<<1<<'\n';
else{
int g=v[0],h=0;
bool b=true;
while(b)
{
h++;
int temp=v[0]/2,temp2=v[0]-temp;
v.erase(v.begin());
int size=v.size();
int start=0,end=v.size()-1;
while(start<end)
{
int middle=(start+end)/2;
if(v[middle]>temp)start=middle+1;
else if(v[middle]<temp)end=middle-1;
else break;
}
int sh=start;
if(temp<v[start])
while(temp<v[start] && start<size) start++;
else if(temp>v[start])
{while(temp>v[start] && start>=0)start--;
start++;
}
v.insert(v.begin()+start,temp);
start = sh;
temp=temp2;
if(temp<v[start])
while(temp<v[start] && start<size) start++;
else if(temp>v[start])
{
while(temp>v[start] && start>=0)start--;
start++;
}
v.insert(v.begin()+start,temp);
g=min(g,v[0]+h);
if(v[0]==v[1])b=false;
}
cout<<"Case #"<<i<<": "<<g<<'\n';}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBmKGludCBpLGludCBqKXtyZXR1cm4gaT5qO30KCmludCBtYWluKCkKewogICAgaW50IHQsZDsKICAgIGNpbj4+dDsKICAgIGZvcihpbnQgaT0xO2k8PXQ7aSsrKQogICAgewogICAgICAgIGNpbj4+ZDsKICAgICAgICB2ZWN0b3I8aW50PiB2KGQpOwogICAgICAgIGZvcihpbnQgaj0wO2o8ZDtqKyspY2luPj52W2pdOwogICAgICAgIHNvcnQodi5iZWdpbigpLHYuZW5kKCksZik7CiAgICAgICAgaWYodlswXT09MSljb3V0PDwiQ2FzZSAjIjw8aTw8IjogIjw8MTw8J1xuJzsKICAgICAgICBlbHNlewogICAgICAgIGludCBnPXZbMF0saD0wOwogICAgICAgIGJvb2wgYj10cnVlOwogICAgICAgIHdoaWxlKGIpCiAgICAgICAgewoKICAgICAgICAgICAgICAgIGgrKzsKICAgICAgICAgICAgICAgIGludCB0ZW1wPXZbMF0vMix0ZW1wMj12WzBdLXRlbXA7CiAgICAgICAgICAgICAgICB2LmVyYXNlKHYuYmVnaW4oKSk7CiAgICAgICAgICAgICAgICBpbnQgc2l6ZT12LnNpemUoKTsKICAgICAgICAgICAgICAgIGludCBzdGFydD0wLGVuZD12LnNpemUoKS0xOwogICAgICAgICAgICAgICAgd2hpbGUoc3RhcnQ8ZW5kKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGludCBtaWRkbGU9KHN0YXJ0K2VuZCkvMjsKICAgICAgICAgICAgICAgICAgICBpZih2W21pZGRsZV0+dGVtcClzdGFydD1taWRkbGUrMTsKICAgICAgICAgICAgICAgICAgICBlbHNlIGlmKHZbbWlkZGxlXTx0ZW1wKWVuZD1taWRkbGUtMTsKICAgICAgICAgICAgICAgICAgICBlbHNlIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaW50IHNoPXN0YXJ0OwogICAgICAgICAgICAgICAgaWYodGVtcDx2W3N0YXJ0XSkKICAgICAgICAgICAgICAgICAgd2hpbGUodGVtcDx2W3N0YXJ0XSAmJiBzdGFydDxzaXplKSBzdGFydCsrOwogICAgICAgICAgICAgICAgZWxzZSBpZih0ZW1wPnZbc3RhcnRdKQogICAgICAgICAgICAgICAge3doaWxlKHRlbXA+dltzdGFydF0gJiYgc3RhcnQ+PTApc3RhcnQtLTsKICAgICAgICAgICAgICAgICBzdGFydCsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdi5pbnNlcnQodi5iZWdpbigpK3N0YXJ0LHRlbXApOwogICAgICAgICAgICAgICAgc3RhcnQgPSBzaDsKICAgICAgICAgICAgICAgIHRlbXA9dGVtcDI7CiAgICAgICAgICAgICAgICBpZih0ZW1wPHZbc3RhcnRdKQogICAgICAgICAgICAgICAgICB3aGlsZSh0ZW1wPHZbc3RhcnRdICYmIHN0YXJ0PHNpemUpIHN0YXJ0Kys7CiAgICAgICAgICAgICAgICBlbHNlIGlmKHRlbXA+dltzdGFydF0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgd2hpbGUodGVtcD52W3N0YXJ0XSAmJiBzdGFydD49MClzdGFydC0tOwogICAgICAgICAgICAgICAgICAgIHN0YXJ0Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB2Lmluc2VydCh2LmJlZ2luKCkrc3RhcnQsdGVtcCk7CiAgICAgICAgICAgICAgICBnPW1pbihnLHZbMF0raCk7CiAgICAgICAgICAgICAgICBpZih2WzBdPT12WzFdKWI9ZmFsc2U7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PCJDYXNlICMiPDxpPDwiOiAiPDxnPDwnXG4nO30KICAgIH0KICAgIHJldHVybiAwOwp9Cg==