Coaches

두 코치가 각각 주기 a일과 b일마다 자리를 비우는데, 시작 시점을 자유롭게 정해 아침과 오후 모두에 코치가 남아 훈련할 수 있는 날의 최댓값을 구한다.

어려움8수학정수론그리디구현아직 제출이 없습니다시간 제한4초메모리 제한256 MB

문제

The University of Bithuania team has qualified for the ACM ICPC world finals! Now the teams's coaches, Martin and Micheal, would like to prepare the team as well as possible. To achieve this goal, they would like to set up a training routine for the next nn days. For a training to be carried out at a given day, they need to print tasks and launch web competition system in the morning and discuss the solutions with contestants in the afternoon.

Both Martin and Michael show up at the university every day. Usually, Martin is there every morning, but every exactly aa days, he needs to settle some things at the local government office, so at these days he is at the university in the afternoon. Likewise, Michael is usually at the university every afternoon, but every bb days he goes to the cinema with his girlfriend, so at these days he shows up in the morning. If no coach is present at the university in the morning or in the afternoon, the training must be called off.

Martin can choose at which of the following aa days he will go to the office for the first time. Similarly, Michael can choose at which of the following bb days he will go to the cinema with his girlfriend for the first time. What is the maximum number of trainings that can be conducted if Martin and Michael determine their schedule optimally?

입력

The first line of the input contains a single integer tt (1t100,0001 \le t \le 100\\,000), the number of test cases in the input. Each of the next tt lines describes a single test case and contains three integers n,a,bn, a, b (1n10181 \le n \le 10^{18}, 1a,b1091 \le a, b \le 10^9) described above.

출력

For each test case, you should output a single integer -- the maximum number of days at which a traning can be conducted.

힌트

In the first example, Martin and Michael should both deviate from their respective standard day plans for the first time at day 22. Then, the trainings will be conducted during the first 33 days.

In the second example, Martin and Michael should deviate from their standard day plans for the first time at days 55 and 11, respectively. Then, the trainings will be conducted during days 2,4,5,6,82, 4, 5, 6, 8 and 1010.