{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003eThe only difference between easy and hard versions is the maximum value of $$$n$$$\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eYou are given a positive integer number $$$n$$$. You really love \u003cspan class\u003d\"tex-font-style-it\"\u003egood numbers\u003c/span\u003e so you want to find the smallest \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e greater than or equal to $$$n$$$.\u003c/p\u003e\u003cp\u003eThe positive integer is called \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e if it can be represented as a sum of \u003cspan class\u003d\"tex-font-style-bf\"\u003edistinct\u003c/span\u003e powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$30$$$ is a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: $$$30 \u003d 3^3 + 3^1$$$, \u003c/li\u003e\u003cli\u003e $$$1$$$ is a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: $$$1 \u003d 3^0$$$, \u003c/li\u003e\u003cli\u003e $$$12$$$ is a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: $$$12 \u003d 3^2 + 3^1$$$, \u003c/li\u003e\u003cli\u003e but $$$2$$$ is \u003cspan class\u003d\"tex-font-style-bf\"\u003enot\u003c/span\u003e a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: you can\u0027t represent it as a sum of distinct powers of $$$3$$$ ($$$2 \u003d 3^0 + 3^0$$$), \u003c/li\u003e\u003cli\u003e $$$19$$$ is \u003cspan class\u003d\"tex-font-style-bf\"\u003enot\u003c/span\u003e a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: you can\u0027t represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 \u003d 3^2 + 3^2 + 3^0 \u003d 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid), \u003c/li\u003e\u003cli\u003e $$$20$$$ is also \u003cspan class\u003d\"tex-font-style-bf\"\u003enot\u003c/span\u003e a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e: you can\u0027t represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 \u003d 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eNote, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of \u003cspan class\u003d\"tex-font-style-bf\"\u003edistinct\u003c/span\u003e powers of $$$3$$$.\u003c/p\u003e\u003cp\u003eFor the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \\le m$$$) that $$$m$$$ is a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eYou have to answer $$$q$$$ independent queries.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains one integer $$$q$$$ ($$$1 \\le q \\le 500$$$) — the number of queries. Then $$$q$$$ queries follow.\u003c/p\u003e\u003cp\u003eThe only line of the query contains one integer $$$n$$$ ($$$1 \\le n \\le 10^{18}$$$).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each query, print such smallest integer $$$m$$$ (where $$$n \\le m$$$) that $$$m$$$ is a \u003cspan class\u003d\"tex-font-style-it\"\u003egood number\u003c/span\u003e.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e8\n1\n2\n6\n13\n14\n3620\n10000\n1000000000000000000\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n3\n9\n13\n27\n6561\n19683\n1350851717672992089\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}