Gug is having fun with numbers! He starts off with an original number *X*, and can choose between the following operations:

- If
*X*is a multiple of 2, divide*X*by 2. - If
*X*is a multiple of 3, divide it by 3. - Subtract 1 from
*X*.

Gug repeats this until he is happy, which is when *X* becomes 0. Given a list of *N* integers that Gug starts with, determine for each integer *A _{i}*, the minimum operations it takes for Gug to be happy.

The first line of input will contain a single integer, *N*.

The second line of input will contain *N* integers, representing the array *A _{i}*.

The output should contain *N* lines with one integer each, with the integer on the *i*th line representing the number of operations it takes for Gug to be happy if he starts with *X* = *A _{i}*.

Subtask 1 (30%): N = 1, 0 ≤ A_{i} ≤ 1000000..

Subtask 2 (31%): 1 ≤ N ≤ 10^{5}, 0 ≤ A_{i} ≤ 1000000.

Subtask 3 (39%): 1 ≤ N ≤ 10^{5}, 0 ≤ A_{i} ≤ 30000000.

Subtask 4 (0%): Sample Testcases.

5 1 5 3 10 9

1 4 2 4 3

Subtask | Score |
---|---|

1 | 30 |

2 | 31 |

3 | 39 |

4 | 0 |