#P17467. [ICPC 2018 Jiaozuo R] Ultraman vs. Aodzilla and Bodzilla

[ICPC 2018 Jiaozuo R] Ultraman vs. Aodzilla and Bodzilla

Problem Description

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 HPAHP_A and HPBHP_B respectively, and their attack values are ATKAATK_A and ATKBATK_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 ii (i.e. its health point will be decreased by ii) where ii represents that Ultraman has launched ii attacks in total, from the beginning to the present, to these two monsters (and the current attack is the ii-th one). That is to say, during the 11-st second, one of these two monsters will be under an attack of damage 11, during the 22-nd second, one of them, if alive, will be under an attack of damage 22, during the 33-rd second, one of them, if alive, will be under an attack of damage 33, 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 ii-th character in the string is 'A', if the Ultraman chooses to attack Aodzilla during the ii-th second; otherwise, the ii-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 ss and tt, if one string is a prefix of the other, then the one with a shorter length is smaller in lexicographical order. In other cases, ss is smaller than tt in lexicographical order if the first character of ss is smaller than the first character of tt, or in case they are equivalent, the second character of ss is smaller than the second character of tt, etc.The case tt is smaller than ss in lexicographical order is defined similarly as the former case.

Input Format

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

For each test case, the only one line contains four integers HPAHP_A, HPBHP_B, ATKAATK_A and ATKBATK_B, where 1≤HPA,HPB,ATKA,ATKB≤1091 \leq HP_A, HP_B, ATK_A, ATK_B \leq 10^9.

We guarantee that there are at most 100100 test cases with max⁡{HPA,HPB}>103\max \lbrace HP_A, HP_B \rbrace > 10^3.

Output Format

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.

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