1 #include<iostream>
2 #include<algorithm>
3 #include<string.h>
4 #include<math.h>
5 #define ll long long
6 #define IO ios_base::sync_with_stdio(0);cin.tie(0);
7 using namespace std;
8 void deal(ll x)
9 {
10 ll ans = 0;
11 ll k = 1ll;
12 while(x){
13 ans += (x & 1ll) * k;
14 k *= 3ll;
15 x = x >> 1;
16 }
17 cout << ans << endl;
18 }
19 int main()
20 {IO;
21 ll T;
22 cin >> T;
23 for(int i = 1; i <= T; i ++){
24 cout << "case " << i << ": ";
25 ll n;
26 cin >> n;
27 deal(n);
28 }
29 return 0;
30 }