#P9874. K. Three Operations

K. Three Operations

K. Three Operations

Problem Description

Given three integers x,a,bx, a, b. You can do the following three operations several times:

  • set xx to x1x - 1;
  • set xx to x+a2\lfloor \dfrac{x+a}{2} \rfloor;
  • set xx to x+b\lfloor \sqrt{x+b} \rfloor. Calculate the smallest number of operations to set xx to 00.

Input

The input consists of multiple test cases. The first line contains a single integer TT (1T2×1041 \le T \le 2 \times 10 ^ 4) - the number of test cases. Description of the test cases follows. The first line of each test case contains three integers x,a,bx, a, b (0x,a,b10180\leq x, a, b \leq 10 ^ {18}).

Output

For each test case, print one integer - the smallest number of operations to set xx to 00.

Sample Input

5
1 1 4
5 1 4
19 1 9
8 1 0
1145141919810 114514 1919810

Sample Output

1
4
5
3
1389

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)