Given a number n, count minimum steps to minimise it to 1 according to the following criteria:

- If n is divisible by 2 then we may reduce n to n/2.
- If n is divisible by 3 then you may reduce n to n/3.
- Decrement n by 1.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the number n.

**Output:**

Output the minimum steps to minimise the number in a new line for each test case.

**Constraints:**

1<= T <=1000

1<= N <=10000

**Example:**

**Input:**

2

10

6

**Output:**

3

2

Author: sujnesh

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

bhatabhi554 | 317 |

hardikJain5 | 306 |

CodeBuddy | 293 |

Akkki111 | 233 |

clone | 230 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

mazumderrohit8 | 1176 |

RemoveTLE | 1144 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4605 |

Quandray | 4444 |

Login to report an issue on this page.