#include #include typedef struct Item { int weight; int price; int edges; int count; } Item; int main() { int count; scanf("%d", &count); Item arr[16]; arr[0].weight = 1; arr[0].price = 1; arr[0].edges = 0; for (int i = 1; i < 16; i++) { arr[i].weight = (int) pow(3, i); arr[i].edges = 3 * arr[i - 1].edges + 2 * arr[i - 1].weight; arr[i].price = arr[i].weight + arr[i].edges; } while (count--) { int num; scanf("%d", &num); for (int i = 0; i < 16; i++) arr[i].count = 0; int lastI = -1; for (int i = 15; i >= 0; i--) { while (arr[i].weight <= num) { if (lastI == -1) lastI = i; arr[i].count++; num -= arr[i].weight; } } for (int i = lastI; i >= 0; i--) { printf("%d", arr[i].count); if (i > 0) printf(" "); } printf("\n"); } return 0; }