// Arup Guha
// 1/23/2012
// Solution to Proposed Mercer Contest Problem: Calculator Games
import java.util.*;

class pair {

	public int value;
	public int distance;

	public pair(int v, int d) {
		value = v;
		distance = d;
	}
}

public class calc {

	final public static int SIZE = 100;

	/* Note: It turns out that no optimal solution ever exceeds 200
	 *       on the display, and only 1 ever exceeds 150, but I've
	 *       coded this faithful to the description, assuming that
	 *       the programmer does not know that.
	 */
	final public static int MAX = 1000000000;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		// Go through and solve each case.
		int numCases = stdin.nextInt();
		for (int i=0; i<numCases; i++) {

			int start = stdin.nextInt();
			System.out.println(solve(start));
		}
	}

	// Runs a BFS starting at value start, keeping track of
	// all values reached in the range [1..SIZE-1].
	public static int solve(int start) {

		// Nothing is visited yet.
		int[] visited = new int[SIZE];
		for (int i=0; i<SIZE; i++)
			visited[i] = -1;

		// Set up our queue.
		LinkedList<pair> queue = new LinkedList<pair>();
		queue.add(new pair(start, 0));

		int numvisited = 0;
		int max = 0;
		int curlength = 0;

		// Do the BFS.
		while (queue.size() > 0 && numvisited < SIZE-1) {

			pair p = queue.poll();

			// See if the next item from the queue needs to be logged.
			if (p.value > 0 && p.value < SIZE) {

				if (visited[p.value] == -1) {
					visited[p.value] = p.distance;
					numvisited++;
					max = p.distance;

				}
			}

			// Enqueue this item plus 1, if necessary.
			int tryVal = p.value + 1;
			if (tryVal > 0 && tryVal < SIZE && visited[tryVal] == -1) {
				queue.add(new pair(tryVal, p.distance+1));
			}
			else if (tryVal > 0 && tryVal < MAX) {
				queue.add(new pair(tryVal, p.distance+1));
			}

			// Enqueue this item times 3, if necessary.
			tryVal = 3*p.value;
			if (tryVal > 0 && tryVal < SIZE && visited[tryVal] == -1) {
				queue.add(new pair(tryVal, p.distance+1));
			}
			else if (tryVal > 0 && tryVal < MAX) {
				queue.add(new pair(tryVal, p.distance+1));
			}

			// Enqueue this item divided by 2, if necessary.
			tryVal = p.value/2;
			if (tryVal > 0 && tryVal < SIZE && visited[tryVal] == -1) {
				queue.add(new pair(tryVal, p.distance+1));
			}
			else if (tryVal > 0 && tryVal < MAX) {
				queue.add(new pair(tryVal, p.distance+1));
			}

		}

		// This was the most number of button presses we needed.
		return max;
	}
}