#include #define FOR(i,a,b) for(int i = (a); i < (b); i++) using namespace std; int main(){ int n; cin >> n; int k[15]; int r[15]; int t = 1; FOR(i,0,15){ k[i] = t; t *= 3; } FOR(i,0,n){ FOR(j,0,15) r[j] = 0; int x; cin >> x; int s = 14; while(x > 0){ while(x >= k[s]){ x -= k[s]; r[s]++; } s--; } bool flag = false, first = false; FOR(j,0,15) { if(r[14-j] > 0)flag = true; if(flag){ if(first) cout << " "; cout << r[14-j]; first = true; } } cout << endl; } }