405661: GYM102028 B Ultraman vs. Aodzilla and Bodzilla

Memory Limit:1024 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Ultraman vs. Aodzilla and Bodzillatime limit per test2.0 smemory limit per test1024 megabytesinputstandard inputoutputstandard output

Six months ago our hero, formerly known as Huriyyah, was beating all monsters in the land. Now he changed his name to Ultraman and left his beloved land. He is ready to take on a new challenge.

In a remote land, local citizens are suffering from the harassment of two powerful and horrible monsters: Aodzilla and Bodzilla. They eat small children who go out alone and even kill innocent persons. The apprehension of being attacked has overwhelmed people for several decades.

For the good of these unfortunate citizens, Ultraman sets out for the forest which is the main lair of Aodzilla and Bodzilla. In the forest, he faces these two fierce and cruel monsters and fights with them. The health points of Aodzilla and Bodzilla are $$$HP_A$$$ and $$$HP_B$$$ respectively, and their attack values are $$$ATK_A$$$ and $$$ATK_B$$$ respectively.

They fight in a cave through turn-based battles. During each second, the Ultraman will be attacked by monsters at first, and the damage is the sum of attack values of all alive monsters. Then he will select exactly one monster which is still alive and attack it. The selected monster will suffer a damage of value $$$i$$$ (i.e. its health point will be decreased by $$$i$$$) where $$$i$$$ represents that Ultraman has launched $$$i$$$ attacks in total, from the beginning to the present, to these two monsters (and the current attack is the $$$i$$$-th one). That is to say, during the $$$1$$$-st second, one of these two monsters will be under an attack of damage $$$1$$$, during the $$$2$$$-nd second, one of them, if alive, will be under an attack of damage $$$2$$$, during the $$$3$$$-rd second, one of them, if alive, will be under an attack of damage $$$3$$$, and so on. If at some time, the health point of a monster is less than or equal to zero, it will die immediately. The Ultraman will win if both monsters have been killed.

Now, you are asked to develop a strategy to minimize the total damage Ultraman should suffer before he wins the battle. A strategy can be described as a string whose length is the total time that the battle will last. The $$$i$$$-th character in the string is 'A', if the Ultraman chooses to attack Aodzilla during the $$$i$$$-th second; otherwise, the $$$i$$$-th character is 'B', which means Bodzilla will be the target during that second. You are also asked to find the optimal strategy whose string description is the smallest in lexicographical order among all possible optimal strategies.

For two distinct strings $$$s$$$ and $$$t$$$, if one string is a prefix of the other, then the one with a shorter length is smaller in lexicographical order. In other cases, $$$s$$$ is smaller than $$$t$$$ in lexicographical order if the first character of $$$s$$$ is smaller than the first character of $$$t$$$, or in case they are equivalent, the second character of $$$s$$$ is smaller than the second character of $$$t$$$, etc. The case $$$t$$$ is smaller than $$$s$$$ in lexicographical order is defined similarly as the former case.

Input

The input contains several test cases, and the first line contains a positive integer $$$T$$$ indicating the number of test cases which is up to $$$10^5$$$.

For each test case, the only one line contains four integers $$$HP_A$$$, $$$HP_B$$$, $$$ATK_A$$$ and $$$ATK_B$$$, where $$$1 \leq HP_A, HP_B, ATK_A, ATK_B \leq 10^9$$$.

We guarantee that there are at most $$$100$$$ test cases with $$$\max\{HP_A, HP_B\} > 10^3$$$.

Output

For each test case, output a line containing an integer indicating the minimal total damage Ultraman should suffer, and a string describing the optimal strategy such that the string description is the smallest in lexicographical order among all possible optimal strategies. You should output exactly one whitespace between the number and the string.

ExampleInput
2
5 15 5 25
5 15 25 5
Output
155 BBBBBA
105 AAABBB

加入题单

算法标签: