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