#include const int N = 16; static unsigned edges[N]; static unsigned nodes[N]; void solve(unsigned capacity) { int i = 1; //printf("solving\n"); while(i < N) { //printf("while %u\n", i); if(nodes[i] == 0) { nodes[i] = nodes[i-1] * 3; edges[i] = 2 * nodes[i-1] * i; } if(nodes[i] >= capacity) break; ++i; } for(--i; i >= 0; --i) { int count = 0; while(capacity >= nodes[i]) { capacity -= nodes[i]; ++count; } if(i > 0) printf("%d ", count); else printf("%d\n", count); } } int main() { int tests; nodes[0] = 1; edges[0] = 0; scanf("%d", &tests); for(int i = 0; i < tests; ++i) { unsigned capacity; scanf("%u", &capacity); solve(capacity); } }