#P1872D. Plus Minus Permutation

Plus Minus Permutation

Description

You are given 33 integers — nn, xx, yy. Let's call the score of a permutation^\dagger p1,,pnp_1, \ldots, p_n the following value:

(p1x+p2x++pnxx)(p1y+p2y++pnyy)(p_{1 \cdot x} + p_{2 \cdot x} + \ldots + p_{\lfloor \frac{n}{x} \rfloor \cdot x}) - (p_{1 \cdot y} + p_{2 \cdot y} + \ldots + p_{\lfloor \frac{n}{y} \rfloor \cdot y})

In other words, the score of a permutation is the sum of pip_i for all indices ii divisible by xx, minus the sum of pip_i for all indices ii divisible by yy.

You need to find the maximum possible score among all permutations of length nn.

For example, if n=7n = 7, x=2x = 2, y=3y = 3, the maximum score is achieved by the permutation [2,6,1,7,5,4,3][2,\color{red}{\underline{\color{black}{6}}},\color{blue}{\underline{\color{black}{1}}},\color{red}{\underline{\color{black}{7}}},5,\color{blue}{\underline{\color{red}{\underline{\color{black}{4}}}}},3] and is equal to (6+7+4)(1+4)=175=12(6 + 7 + 4) - (1 + 4) = 17 - 5 = 12.

^\dagger A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in any order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (the number 22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3, but the array contains 44).

The first line of input contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Then follows the description of each test case.

The only line of each test case description contains 33 integers nn, xx, yy (1n1091 \le n \le 10^9, 1x,yn1 \le x, y \le n).

For each test case, output a single integer — the maximum score among all permutations of length nn.

Input

The first line of input contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Then follows the description of each test case.

The only line of each test case description contains 33 integers nn, xx, yy (1n1091 \le n \le 10^9, 1x,yn1 \le x, y \le n).

Output

For each test case, output a single integer — the maximum score among all permutations of length nn.

Sample Input 1

8
7 2 3
12 6 3
9 1 9
2 2 2
100 20 50
24 4 6
1000000000 5575 25450
4 4 1

Sample Output 1

12
-3
44
0
393
87
179179179436104
-6

Note

The first test case is explained in the problem statement above.

In the second test case, one of the optimal permutations will be [12,11,2,4,8,9,10,6,1,5,3,7][12,11,\color{blue}{\underline{\color{black}{2}}},4,8,\color{blue}{\underline{\color{red}{\underline{\color{black}{9}}}}},10,6,\color{blue}{\underline{\color{black}{1}}},5,3,\color{blue}{\underline{\color{red}{\underline{\color{black}{7}}}}}]. The score of this permutation is (9+7)(2+9+1+7)=3(9 + 7) - (2 + 9 + 1 + 7) = -3. It can be shown that a score greater than 3-3 can not be achieved. Note that the answer to the problem can be negative.

In the third test case, the score of the permutation will be (p1+p2++p9)p9(p_1 + p_2 + \ldots + p_9) - p_9. One of the optimal permutations for this case is [9,8,7,6,5,4,3,2,1][9, 8, 7, 6, 5, 4, 3, 2, 1], and its score is 4444. It can be shown that a score greater than 4444 can not be achieved.

In the fourth test case, x=yx = y, so the score of any permutation will be 00.