Anuj has challenged Arun to climb P stairs but at only in powers of X and Y. Now Arun being a lazy guy wants to do this in minimum number of steps possible. So he has asked for your help to calculate the **minimum** number of steps he requires to take for climbing P stairs ( 1 step = some power of X or Y stairs ).

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains 3 space separated integers P, X and Y, where P is the number of stairs to be climbed.

**Output:**

Corresponding to each test case, in a new line, print the number of steps that Arun needs to take to climb P stairs in powers of X & Y. If fit is not possible print -1.

**Constraints:**

1<=T<=200

1<=P,X,Y<=10^5

**Example:**

**Input: **

2

15 2 3

19 4 3

**Output:**

3

2

**Explanation:**

In the first case, we can make 15 by (8,4,3) or (9,3,3) both takes 3 steps.

In the second case, we can make 19 by (16,3) which is 2 steps.

Author: whiteman

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.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.