#include #include #include using namespace std; int find(int arr[], int count, int start) { for(int i = start; i >= 0; i--) { if(count >= arr[i]) return i; } return 0; } int main(void) { int arr[16], out[16]; arr[0] = 1; out[0] = 0; for(int i = 1; i < 16; i++) { arr[i] = arr[i-1]*3; out[i] = 0; } string str; getline(cin, str); int n; sscanf(str.c_str(), "%d", &n); for(int i = 0; i < n; i++) { int count, start = 15; scanf(" %d ", &count); for(int i = 0; i < 16; i++) out[i] = 0; int pos = find(arr, count, start); int right = pos; while(count) { //cout << count << " " << arr[pos] << endl; count -= arr[pos]; out[pos] += 1; start = pos; pos = find(arr, count, start); } for(int j = right; j >= 0; j--) cout << (j != right ? " " : "") << out[j]; cout << endl; } return 0; }