#include #include #include #include #define REP(i, cnt) for (int i = 0; i < (cnt); i++) #define N 19 using namespace std; typedef long long int64; int main() { int dyn[2][N]; int odpoved[N]; int count; dyn[0][0] = 1; dyn[1][0] = 2; for (int j = 1; j < N; j++) { dyn[0][j] = dyn[0][j-1]*3; dyn[1][j] = 2*dyn[0][j]; } /*REP(i, N) printf("%d ", dyn[0][i]); printf("\n"); REP(i, N) printf("%d ", dyn[1][i]); printf("\n"); return 0;*/ scanf("%d", &count); { REP(i, count) { int input; int last = 0; scanf("%d", &input); odpoved[0] = 0; for (int i = N-1; i >= 0; i--) { odpoved[i] = 0; if (dyn[1][i] <= input) { odpoved[i] = 2; } else if (dyn[0][i] <= input) { odpoved[i] = 1; } if (odpoved[i]) { if (!last) last = i; input -= dyn[odpoved[i]-1][i]; } } //printf("l %d\n", last); for (int j = last; j >= 0; j--) printf(j ? "%d " : "%d\n", odpoved[j]); //printf("\n"); } } return 0; }