#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
const int ma =30000005;
int ans[30000005];
void solve()
{
int top=ma >> 1,b;
for(int c=1;c<=top;++c)
{
for(int a=c+c;a<=ma;a+=c){
b=a-c;
if((a^b)==c)++ans[a];
}
}
for(int i=2;i<=ma;++i)ans[i]=ans[i-1]+ans[i];
}
int id=1;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int t;
solve();
scanf("%d",&t);
int num;
while(t--)
{
scanf("%d",&num);
printf("Case %d: %d\n",id++,ans[num]);
}
}