#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e18 + 7 ;
ll expo( ll base , ll pow , ll n) {
ll ans = 1 ;
while ( pow ! = 0 ) {
if ( base > n || base <= 0 ) {
return - 1 ;
}
if ( pow & 1 == 1 ) {
if ( ans > n/ base) return - 1 ;
ans = ans* base;
if ( ans > n|| ans <= 0 ) {
return - 1 ;
}
//ans = ans%mod;
}
if ( base > n/ base) base = mod;
else
base * = base;
// base%=mod;
pow / = 2 ;
}
return ans;
}
/* -------Template ends here-------- */
const int M = 100001 ;
int fits( ll base , int dig , ll n) {
for ( int i = dig - 1 ; i>= 0 ; i-- ) {
ll temp = expo( base , i , n) ;
if ( temp == - 1 )
return - 1 ;
n - = temp;
if ( n< 0 )
return - 1 ;
}
if ( n == 0 )
return 0 ;
return 1 ;
}
int main( ) {
int t;
si( t) ;
for ( int alp = 1 ; alp<= t; alp++ ) {
ll n;
sll( n) ;
ll ans = n - 1 ;
int dig = 1 ;
for ( int digits = 70 ; digits >= 2 ; digits-- ) {
ll lo = 2 , hi = n - 1 ;
int o = 0 ;
while ( lo <= hi) {
ll mid = ( lo + hi + 1 ) / 2 ;
int num = fits( mid , digits , n) ;
if ( num == 0 ) {
ans = mid;
o++ ;
break ;
}
else if ( num == 1 ) { // this base is small
lo = mid + 1 ;
}
else { // this base is large
hi = mid - 1 ;
}
}
if ( o) {
break ;
}
}
cout << "Case #" << alp<< ": " << ans<< endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHNpKFgpIHNjYW5mKCIlZCIsICYoWCkpCiNkZWZpbmUgc2xsKFgpIHNjYW5mKCIlbGxkIiwmKFgpKQoKY29uc3QgbGwgbW9kID0gMWUxOCs3OwpsbCBleHBvKGxsIGJhc2UgLCBsbCBwb3cgLCBsbCBuKXsKICAgIGxsIGFucyA9IDE7CiAgICB3aGlsZShwb3chPTApewogICAgICAgIGlmKGJhc2UgPiBuIHx8IGJhc2UgPD0gMCl7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYocG93JjE9PTEpewogICAgICAgIAlpZihhbnMgPiBuL2Jhc2UpIHJldHVybiAtMTsKICAgICAgICAgICAgYW5zID0gYW5zKmJhc2U7CiAgICAgICAgICAgIGlmKGFucyA+IG58fCBhbnMgPD0gMCl7CiAgICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9hbnMgPSBhbnMlbW9kOwogICAgICAgIH0KICAgICAgICBpZihiYXNlID4gbi9iYXNlKSBiYXNlID0gbW9kOwogICAgICAgIGVsc2UKICAgICAgICAJYmFzZSAqPSBiYXNlOwogICAgICAgLy8gYmFzZSU9bW9kOwogICAgICAgIHBvdy89MjsKCiAgICB9CiAgICByZXR1cm4gYW5zOwp9CgovKiAtLS0tLS0tVGVtcGxhdGUgZW5kcyBoZXJlLS0tLS0tLS0gKi8KCmNvbnN0IGludCBNID0gMTAwMDAxOwoKCmludCBmaXRzKGxsIGJhc2UgLCBpbnQgZGlnICwgbGwgbil7CiAgICBmb3IoaW50IGkgPSBkaWcgLSAxIDsgaT49MCA7IGktLSl7CiAgICAgICAgbGwgdGVtcCA9IGV4cG8oYmFzZSAsIGkgLCBuKTsKICAgICAgICBpZih0ZW1wID09IC0xKQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgbiAtPSB0ZW1wOwogICAgICAgIGlmKG48MCkKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgaWYobiA9PSAwKQogICAgICAgIHJldHVybiAwOwogICAgcmV0dXJuIDE7Cn0KaW50IG1haW4oKXsKICAgIAoJaW50IHQ7CglzaSh0KTsKCglmb3IoaW50IGFscCA9IDE7YWxwPD10O2FscCsrKXsKCQkKICAgICAgICBsbCBuOwogICAgICAgIHNsbChuKTsKICAgICAgICBsbCBhbnMgPSBuIC0gMTsKICAgICAgICBpbnQgZGlnID0gMTsKCiAgICAgICAgZm9yKGludCBkaWdpdHMgPSA3MCA7IGRpZ2l0cyA+PSAyIDsgZGlnaXRzLS0pewogICAgICAgICAgICBsbCBsbyA9IDIgLCBoaSA9IG4gLSAxOwogICAgICAgICAgICBpbnQgbyA9IDA7CiAgICAgICAgICAgIHdoaWxlKGxvIDw9IGhpKXsKICAgICAgICAgICAgICAgIGxsIG1pZCA9IChsbyArIGhpICsgMSkvMjsKICAgICAgICAgICAgICAgIGludCBudW0gPSBmaXRzKG1pZCAsIGRpZ2l0cyAsIG4pOwogICAgICAgICAgICAgICAgaWYobnVtID09IDApewogICAgICAgICAgICAgICAgICAgIGFucyA9IG1pZDsKICAgICAgICAgICAgICAgICAgICBvKys7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlIGlmKG51bSA9PSAxKXsgICAgICAgICAgICAgICAgICAgICAvLyB0aGlzIGJhc2UgaXMgc21hbGwKICAgICAgICAgICAgICAgICAgICBsbyA9IG1pZCArIDE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNleyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gdGhpcyBiYXNlIGlzIGxhcmdlCiAgICAgICAgICAgICAgICAgICAgaGkgPSBtaWQgLSAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKG8pewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CgoKCgoKCQljb3V0PDwiQ2FzZSAjIjw8YWxwPDwiOiAiPDxhbnM8PGVuZGw7CgoJfQoKfQ==
stdin
MTAwCjE0OTE5OTIxNDQzNzEzNzc3CjE2MDM1NzEzNzEyOTEwNjI3CjQ3MDk4ODg4NDg4MTQwMzcwMQo2NjMyM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1MTYyMjc4NjUzNjI2Mzg0MTAKMTA2OTU0Mjk0Mjg1OTkyMTE1CjU4ODYwODQyNjMyMTI1NzAwCjQ0NjQwMTU1OTQ2OTM2ODk1NAo5MDAwNzU4MTg5NDczMjM5NDAKODEzOTE4MjA5OTE0ODM0NzUzCjgwMzExNzkxMTAyOTczMDMxMwoxMzA0NjM4OTkzNTEzNzYxMzcKNjk4MDQ1MjM5Mjg5Mjk4Nwo2NjYxMzcxMTAxMTI4MDI4MAozMTExMTkzNTQ0MDMzNzY3OTMKMTE0MzQ5OTAwMTQ1NTg0MTI5CjE4Mjg1OTc3Nzk0MDAwMDk4MA==
100
14919921443713777
16035713712910627
470988884881403701
663208457429249320
35417244247309081
18912140357306197
821424692950225218
194148123592167400
169683965173070355
30896151154490161
8152332946963171
26504196177401065
727004545306745403
1000000000000000000
210724372007205925
230839591399678411
139782788180007861
31108559476176585
70640308161049884
919818571896748567
805068181058041870
528077080918778560
3392264354546656
172589956609631527
752116768933572174
278385972618095971
500364605967785712
936501597464173890
5346848976102943
42711799474754936
39739406344976521
96642126154887385
507373618559718949
148522861921131118
5990709545080807
58873926717610501
779668738937986840
34824506845925071
131226544799105148
14500751095055161
541064907662839644
665930169964312773
2854907964745564
151970818238211610
916365355264637559
353896329635329936
625318600331879360
690683275350237133
31899883679471306
99670604181093725
736827088955709913
113836064401097977
8508110325218143
13321050162245608
609649911611389831
46268622795238201
468339557884957084
25965247599543841
381252133354068211
494196153725539231
945648548682242665
19337682799995045
619861907468053901
229239004074282805
386581418747680
610260633162639678
299694296458966143
845078653019833051
373345485670171062
27233228344819564
129023667184858285
83124300916686757
379255974823102021
245249591795535097
43969534069696
66722517469920
9858438270839893
6910943299863520
25717131834499624
92023103018361641
943990493461794871
513767149194597040
112064524403878803
174210760090244515
5811353213141560
85718519097865885
984245729893369243
516227865362638410
106954294285992115
58860842632125700
446401559469368954
900075818947323940
813918209914834753
803117911029730313
130463899351376137
6980452392892987
66613711011280280
311119354403376793
114349900145584129
182859777940000980