Problem Description

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

  1. If X is a multiple of 2, divide X by 2.
  2. If X is a multiple of 3, divide it by 3.
  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 Ai, the minimum operations it takes for Gug to be happy.

Input

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

The second line of input will contain N integers, representing the array Ai.

Output

The output should contain N lines with one integer each, with the integer on the ith line representing the number of operations it takes for Gug to be happy if he starts with X = Ai.

Limits

Subtask 1 (30%): N = 1, 0 ≤ Ai ≤ 1000000..

Subtask 2 (31%): 1 ≤ N ≤ 105, 0 ≤ Ai ≤ 1000000.

Subtask 3 (39%): 1 ≤ N ≤ 105, 0 ≤ Ai ≤ 30000000.

Subtask 4 (0%): Sample Testcases.

Sample Input 1

5
1 5 3 10 9

Sample Output 1

1
4
2
4
3