#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define ll long long
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
const ll mod = 2e18;
const int N = 3e5;
vi g[N];
int a[N];
ll mpow(ll base, ll exp);
string s;
vll cnt;
int dig;
ll y;
bool f(ll val){
ll sum = 1;
ll beg = val;
int x = 1;
while(sum<y and x<dig){
x++;
if(sum >= y) return 1;
sum += beg;
if(beg >= y/val and x<dig) return 1;
beg *= val;
}
return sum>=y;
}
bool check(ll val){
ll sum = 1;
ll beg = val;
int x = 1;
while(sum<y and x<dig){
x++;
if(sum > y) return 0;
sum += beg;
beg *= val;
}
return sum==y;
}
ll bin(ll lo, ll hi){
if(lo==hi){
if(f(lo))
return lo;
return -1;
}
if(lo+1==hi){
if(f(lo))
return lo;
if(f(hi))
return hi;
return -1;
}
ll mid = (lo+hi)/2;
if(f(mid)) return bin(lo, mid);
return bin(mid+1, hi);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i,n,k,j;
int T , t;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>t; T = t;
for(int zz = 1; zz <= T; zz++){
cout<<"Case #"<<zz<<": ";
cin>>y;
ll x;
Fo(dig, 64,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