// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;
int main() {
// freopen("army.in","r",stdin);
int T;
scanf(" %d",&T);
for(int t =0; t < T; t++) {
long long N;
scanf(" %lld",&N);
long long a =0, b =2000000;
while(b-a > 1) {
long long c =(a+b)/2;
long long s =c*(c+1)*(2*c+1)/6;
if(s >= N) b =c;
else a =c;}
long long ans =a*a;
N -=a*(a+1)*(2*a+1)/6;
if(N <= b*(b+1)/2) {
a =-1;
while(b-a > 1) {
long long c =(b+a)/2;
if(c*(c+1)/2 >= N) b =c;
else a =c;}
ans +=b;}
else {
ans +=2*b-1;
N =b*b-N;
a =0;
while(b-a > 1) {
long long c =(b+a)/2;
if(c*(c+1)/2 > N) b =c;
else a =c;}
ans -=a;}
printf("Case %d: %lld\n",t+1,ans);}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb21hbmlwPgojZGVmaW5lIGRpYnMgcmVzZXJ2ZQojZGVmaW5lIE9WRVI5MDAwIDEyMzQ1Njc4OTAKI2RlZmluZSBwYXRrY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