Score : $1100$ points
Let $f(A, B)$, where $A$ and $B$ are positive integers, be the string satisfying the following conditions:
A
and exactly $B$ letters B
;AAAAA
or BBBB
) is as small as possible under the conditions above;For example, $f(2, 3)$ = BABAB
, and $f(6, 4)$ = AABAABAABB
.
Answer $Q$ queries: find the substring of $f(A_i, B_i)$ from position $C_i$ to position $D_i$ (1-based).
Input is given from Standard Input in the following format:
$Q$ $A_1$ $B_1$ $C_1$ $D_1$ $A_2$ $B_2$ $C_2$ $D_2$ $:$ $A_Q$ $B_Q$ $C_Q$ $D_Q$
For each query $i$ in order of input, print a line containing the substring of $f(A_i, B_i)$ from position $C_i$ to position $D_i$ (1-based).
5 2 3 1 5 6 4 1 10 2 3 4 4 6 4 3 7 8 10 5 8
BABAB AABAABAABB A BAABA ABAB