#C9023. Taco Collatz Sequence Generator

    ID: 53071 Type: Default 1000ms 256MiB

Taco Collatz Sequence Generator

Taco Collatz Sequence Generator

You are given a positive integer n. Your task is to generate a special sequence starting from n and ending at 1 by applying the following rules until the sequence terminates:

If \( n \) is even, then \( n \) becomes \( \frac{n}{2} \).

If \( n \) is odd, then \( n \) becomes \( 3n+1 \).

For example, if \( n = 3 \), the sequence is:

\[ 3,\;10,\;5,\;16,\;8,\;4,\;2,\;1 \]

You need to handle multiple test cases.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer t representing the number of test cases.
  • The next t lines each contain one integer n.

For each test case, generate the corresponding sequence.

outputFormat

For each test case, output the generated sequence in a single line. The numbers in the sequence should be separated by a single space, and each test case's output should be printed on a new line. The output is written to standard output (stdout).

## sample
3
3
6
10
3 10 5 16 8 4 2 1

6 3 10 5 16 8 4 2 1 10 5 16 8 4 2 1

</p>