#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
char s[maxn];
typedef long long ll;
ll k;
int main()
{
int _;
cin>>_;
int ca = 1;
while(_--)
{
scanf("%lld",&k);
scanf("%s",s);
if(k==0)
{
printf("Case #%d: 0\n",ca++);
continue;
}
int len = strlen(s);
ll ans = 0;
for(int i = 0;i < len && i < k;++i)
{
ans = ans*2+(s[i]-'0');
}
ll sum = ans;
for(int i = k;i < len;i++)
{
sum = (sum - (s[i-k]-'0')*(1ll << (k-1)))*2+(s[i]-'0');
ans = max(ans,sum);
}
printf("Case #%d: %lld\n",ca++,ans);
}
return 0;
}
/*
100
1
10101
1
10101
3
10101
5
10101
*/