#P8491. Guaranteed Prisoner Liberation
Guaranteed Prisoner Liberation
Guaranteed Prisoner Liberation
A prison houses 500 prisoners. One day, the warden offers them a chance at freedom if they can correctly identify the bag with the fewer coins. Two bags, A and B, are placed in a room. Each bag contains a number of coins, and the coin count in each bag is an integer in the range \( [1, N]\) (inclusive). Importantly, the two bags contain different numbers of coins.
In the room, there is also a whiteboard that initially displays the number \(0\). The prisoners enter the room one by one. When a prisoner enters:
- The prisoner looks at the number \(i\) written on the whiteboard (with \(0 \le i \le x\), where \(x\) is a non-negative integer chosen in advance by all prisoners during their pre-challenge meeting).
- They then decide, based on a prearranged strategy, which bag to inspect (either bag A or bag B). The strategy specifies for every board number \(i,\) which bag to check.
- After checking the chosen bag, the prisoner learns the coin count \(j\) in that bag (with \(1 \le j \le N\)). Then, based on both \(i\) and \(j\) (and following the prearranged strategy that assigns an action for every pair \((i, j)\)), he must either:
- Rewrite the whiteboard with a new number (which can be any non-negative integer between \(0\) and \(x\), possibly the same as \(i\)), and then leave the room, or
- Announce which bag (A or B) he believes has the fewer coins. This announcement immediately ends the challenge.
The challenge is won if a prisoner correctly identifies the bag with fewer coins; if the wrong bag is chosen, or if none of the 500 prisoners ever announce a bag, the prisoners lose. Moreover, if the challenge is won, the warden will release the prisoners after \(x\) days of continued imprisonment.
The prisoners have time to convene before the challenge begins. They can discuss and agree on a strategy that involves three main decisions:
- Choosing a non-negative integer \(x\) (the maximum number that might be written on the whiteboard).
- Deciding, for every number \(i\) with \(0 \le i \le x\), which bag (A or B) a prisoner should inspect when the whiteboard shows \(i\).
- Deciding, for every combination of whiteboard number \(i\) (with \(0 \le i \le x\)) and inspected bag coin count \(j\) (with \(1 \le j \le N\)), whether the prisoner should update the whiteboard with a new number (also between \(0\) and \(x\)) or announce a bag as having fewer coins.
Your task is to implement a program that, given two distinct coin counts (simulating the content of bags A and B) as input, outputs the correct bag with the fewer coins. This simplified version abstracts away the prisoners and whiteboard dynamics and focuses on the final outcome of the challenge.
Note: All mathematical formulas are formatted in LaTeX. For example, ranges are given as \( [1, N]\) and board numbers as \(0 \le i \le x\).
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains two space-separated integers \(A\) and \(B\) (with \(1 \le A, B \le N\) and \(A \neq B\)) representing the number of coins in bag A and bag B, respectively.
outputFormat
For each test case, output a single line containing a single uppercase letter:
A if bag A contains the fewer coins, or
B if bag B contains the fewer coins.
sample
1
1 2
A
</p>