#include #include using namespace std; int main() { int numInput; cin >> numInput; for (int i = 0; i < numInput; i++) { int capacity = 0; cin >> capacity; if (capacity == 1) { cout << "1" << endl; continue; } int n = 0; while ((int)pow(3,n) < capacity) { n++; } capacity = (int)capacity % (int)pow(3, n); n--; while (n > 0) { cout << capacity / (int)pow(3, n) << " "; capacity = (int)capacity % (int)pow(3, n); n--; } cout << capacity / (int)pow(3, n); cout << endl; } return 0; }