//Author : Ujjawal Dixit , ABV-IIITM
//Task : test
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
using namespace std;
typedef double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define FOR(i,n,m) for(int i=0;i<n;i+=m)
#define For(i,n,m) for(int i=1;i<=n;i+=m)
#define max(a,b) (a>=b?a:b)
#define min(a,b) (a<b?a:b)
#define countbits(num) __builtin_popcount(num)
#define countbitsll(num) __builtin_popcountll(num)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define p(a) printf("%d",a)
#define pll(a) printf("%lld",a)
#define pln() printf("\n")
#define getstr(in) getline(cin,in)
#define getc() getchar()
#define uj() int t; scanf("%d",&t); while(t--)
ll mpow(ll a, ll n)
{ll ret=1;ll b=a;while(n) {if(n&1)
ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (ll)ret;}
template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}
vector<int> arr;
int *chk_arr;
void fn(long long c_in,long long d,long long v)
{
d=arr.size();
double check=pow(c_in+1,d)-1;
for(int i=0;i<=check;i++)
{
long long binary[d]={0};
long long c=0;
long long sum=0;
int temp=i;
while(temp)
{
binary[c++]=temp%(c_in+1);
temp/=(c_in+1);
}
for(int k=0;k<d;k++)
{
if(binary[k]!=0)
{
sum+=(binary[k]*arr[k]);
}
}
if(sum<=v)
chk_arr[sum]=1;
}
}
int main() {
int t;
cin>>t;
for(int cases=1;cases<=t;cases++)
{
long long c,d,v;
cin>>c>>d>>v;
//vector<int> arr(d);
arr.resize(d);
chk_arr=(int*)malloc(sizeof(int)*v);
for(long long i=0;i<d;i++)
cin>>arr[i];
chk_arr[0]=1;
long long count=0;
// int curr_sum, i, j;
while(1)
{
long long add=-1;
fn(c,d,v);
for(long long i=0;i<=v;i++)
{//cout<<"\ni "<<i<<" "<<chk_arr[i];
if(chk_arr[i]!=1)
{add=i;break;}
}
if(add==-1)
break;
else
{arr.push_back(add);count++;}
}
// cout<<count<<"\n";
cout<<"Case #"<<cases<<": "<<count<<"\n";
}
return 0;
}
Ly9BdXRob3IgOiBVamphd2FsIERpeGl0ICAsIEFCVi1JSUlUTQovL1Rhc2sgOiB0ZXN0CgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIE1BWCAxZTkKI2RlZmluZSBNSU4gLTFlOQp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGRvdWJsZSBsZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7IAp0eXBlZGVmIHZlY3Rvcjx2aT4gdnZpOyAKdHlwZWRlZiBwYWlyPGludCxpbnQ+IGlpOyAKI2RlZmluZSBGT1IoaSxuLG0pIGZvcihpbnQgaT0wO2k8bjtpKz1tKQojZGVmaW5lIEZvcihpLG4sbSkgZm9yKGludCBpPTE7aTw9bjtpKz1tKQojZGVmaW5lIG1heChhLGIpICAgIChhPj1iP2E6YikKI2RlZmluZSBtaW4oYSxiKSAgICAoYTxiP2E6YikKI2RlZmluZSBjb3VudGJpdHMobnVtKSAgIF9fYnVpbHRpbl9wb3Bjb3VudChudW0pCiNkZWZpbmUgY291bnRiaXRzbGwobnVtKSAgIF9fYnVpbHRpbl9wb3Bjb3VudGxsKG51bSkKI2RlZmluZSBzKGEpIHNjYW5mKCIlZCIsJmEpCiNkZWZpbmUgc2xsKGEpIHNjYW5mKCIlbGxkIiwmYSkKI2RlZmluZSBwKGEpIHByaW50ZigiJWQiLGEpCiNkZWZpbmUgcGxsKGEpIHByaW50ZigiJWxsZCIsYSkKI2RlZmluZSBwbG4oKSAgcHJpbnRmKCJcbiIpCiNkZWZpbmUgZ2V0c3RyKGluKSBnZXRsaW5lKGNpbixpbikKI2RlZmluZSBnZXRjKCkgZ2V0Y2hhcigpCiNkZWZpbmUgdWooKSBpbnQgdDsgc2NhbmYoIiVkIiwmdCk7IHdoaWxlKHQtLSkKbGwgbXBvdyhsbCBhLCBsbCBuKSAKe2xsIHJldD0xO2xsIGI9YTt3aGlsZShuKSB7aWYobiYxKSAKICAgIHJldD0ocmV0KmIpJU1PRDtiPShiKmIpJU1PRDtuPj49MTt9CiAgICByZXR1cm4gKGxsKXJldDt9CnRlbXBsYXRlPHR5cGVuYW1lIFQ+IFQgZ2NkKFQgYSwgVCBiKSB7CiAgICBpZighYikgcmV0dXJuIGE7CiAgICByZXR1cm4gZ2NkKGIsIGEgJSBiKTsKfQp0ZW1wbGF0ZTx0eXBlbmFtZSBUPiBUIGxjbShUIGEsIFQgYikgewogICAgcmV0dXJuIGEgKiBiIC8gZ2NkKGEsIGIpOwp9Cgp2ZWN0b3I8aW50PiBhcnI7CmludCAqY2hrX2FycjsKdm9pZCBmbihsb25nIGxvbmcgY19pbixsb25nIGxvbmcgZCxsb25nIGxvbmcgdikKICAgIHsKICAgIGQ9YXJyLnNpemUoKTsKICAgIGRvdWJsZSBjaGVjaz1wb3coY19pbisxLGQpLTE7CiAgICAgICAgZm9yKGludCBpPTA7aTw9Y2hlY2s7aSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgIGxvbmcgbG9uZyBiaW5hcnlbZF09ezB9OwogICAgICAgICAgICBsb25nIGxvbmcgYz0wOwogICAgICAgICAgICBsb25nIGxvbmcgc3VtPTA7CiAgICAgICAgICAgIGludCB0ZW1wPWk7CiAgICAgICAgICAgIHdoaWxlKHRlbXApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBiaW5hcnlbYysrXT10ZW1wJShjX2luKzEpOwogICAgICAgICAgICAgICAgdGVtcC89KGNfaW4rMSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKGludCBrPTA7azxkO2srKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGJpbmFyeVtrXSE9MCkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgc3VtKz0oYmluYXJ5W2tdKmFycltrXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoc3VtPD12KQogICAgICAgICAgICAgICAgY2hrX2FycltzdW1dPTE7CiAgICAgICAgICAgIAogICAgICAgIH0KfQppbnQgbWFpbigpIHsKICAgIGludCB0OwogICAgY2luPj50OwogICAgZm9yKGludCBjYXNlcz0xO2Nhc2VzPD10O2Nhc2VzKyspCiAgICAgICAgewogICAgICAgIGxvbmcgbG9uZyBjLGQsdjsKICAgICAgICBjaW4+PmM+PmQ+PnY7CiAgICAgICAgLy92ZWN0b3I8aW50PiBhcnIoZCk7CiAgICAgICAgCiAgICAgICAgYXJyLnJlc2l6ZShkKTsKICAgICAgICBjaGtfYXJyPShpbnQqKW1hbGxvYyhzaXplb2YoaW50KSp2KTsKICAgICAgICBmb3IobG9uZyBsb25nIGk9MDtpPGQ7aSsrKQogICAgICAgICAgICBjaW4+PmFycltpXTsKICAgICAgICAKICAgICAgICBjaGtfYXJyWzBdPTE7CiAgICAgICAgbG9uZyBsb25nIGNvdW50PTA7CiAgICAvLyAgICAgaW50IGN1cnJfc3VtLCBpLCBqOwogCiAgICAgICAgIAogICAgICAgIHdoaWxlKDEpCiAgICAgICAgewogICAgICAgICAgICBsb25nIGxvbmcgYWRkPS0xOwogICAgICAgICAgICBmbihjLGQsdik7CiAgICAgICAgCiAgICAgICAgICAgIGZvcihsb25nIGxvbmcgaT0wO2k8PXY7aSsrKQogICAgICAgIHsvL2NvdXQ8PCJcbmkgIjw8aTw8IiAiPDxjaGtfYXJyW2ldOwogICAgICAgICBpZihjaGtfYXJyW2ldIT0xKQogICAgICAgICB7YWRkPWk7YnJlYWs7fQogICAgICAgIH0KICAgICAgICAgICAgaWYoYWRkPT0tMSkKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHthcnIucHVzaF9iYWNrKGFkZCk7Y291bnQrKzt9CiAgICAgICAgfQogICAgLy8gY291dDw8Y291bnQ8PCJcbiI7CiAgICAgICAgY291dDw8IkNhc2UgIyI8PGNhc2VzPDwiOiAiPDxjb3VudDw8IlxuIjsKCiAgICB9CgoKICAgIHJldHVybiAwOwp9