#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
using namespace std;
unsigned long long base = 1;
int main(){
//freopen("1.txt","r",stdin);
int n,length;
unsigned long long digit = 0;
char str[100];
char NewStr[100];
scanf("%d",&n);
while(n--){
digit = 0;
memset(str,0,sizeof(str));
memset(NewStr,0,sizeof(NewStr));
cin >> str;
base = 1;
length = strlen(str);
for(int j = length - 1; j >= 0; --j){
digit += (long long)(str[j] - '0') * base;
base *= 2;
}
if(digit == 0){
printf("0\n");
continue;
}
int i = 0;
while(digit > 0){
NewStr[i++] = digit % 3 + '0';
digit /= 3;
}
NewStr[i] = '\0';
for(int k = i -1; k >= 0; --k){
printf("%c",NewStr[k]);
}
printf("\n");
}
return 0;
}
没有什么算法~不过要考虑边界条件还有就是数据类型要用unsigned long long