import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam056 */ public class Lode { static StringTokenizer tokenizer = new StringTokenizer(""); static BufferedReader reader; static String nextToken() throws Exception { if (tokenizer.hasMoreTokens()) { return tokenizer.nextToken(); } String line = reader.readLine(); if (line != null) { tokenizer = new StringTokenizer(line); return nextToken(); } return null; } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); int numLines = Integer.parseInt(nextToken()); for (int i = 0; i < numLines; i++) { int capacity = Integer.parseInt(nextToken()); int res = 1; while (res <= capacity) { res *= 3; } res /= 3; while (res >= 1) { System.out.printf("%d", capacity / res); capacity -= capacity / res * res; res /= 3; if (res >= 1) { System.out.print(" "); } } System.out.println(""); } } }