CF1977B.Binary Colouring

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Binary Colouring

You are given a positive integer xx. Find any array of integers a0,a1,,an1a_0, a_1, \ldots, a_{n-1} for which the following holds:

  • 1n321 \le n \le 32,
  • aia_i is 11, 00, or 1-1 for all 0in10 \le i \le n - 1,
  • $x = \displaystyle{ um_{i=0}^{n - 1}{a_i \cdot 2^i}}$,
  • There does not exist an index 0in20 \le i \le n - 2 such that both ai0a_{i} \neq 0 and ai+10a_{i + 1} \neq 0.

It can be proven that under the constraints of the problem, a valid array always exists.

Input

Each test contains multiple test cases. The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single positive integer xx (1x<2301 \le x \lt 2^{30}).

Output

For each test case, output two lines.

On the first line, output an integer nn (1n321 \le n \le 32) — the length of the array a0,a1,,an1a_0, a_1, \ldots, a_{n-1}.

On the second line, output the array a0,a1,,an1a_0, a_1, \ldots, a_{n-1}.

If there are multiple valid arrays, you can output any of them.

Note

In the first test case, one valid array is [1][1], since (1)20=1(1) \cdot 2^0 = 1.

In the second test case, one possible valid array is [0,1,0,0,1][0,-1,0,0,1], since $(0) \cdot 2^0 + (-1) \cdot 2^1 + (0) \cdot 2^2 + (0) \cdot 2^3 + (1) \cdot 2^4 = -2 + 16 = 14$.

Samples

7
1
14
24
15
27
11
19
1
1
5
0 -1 0 0 1
6
0 0 0 -1 0 1
5
-1 0 0 0 1
6
-1 0 -1 0 0 1
5
-1 0 -1 0 1
5
-1 0 1 0 1

在线编程 IDE

建议全屏模式获得最佳体验