#AGC020D. [AGC020D] Min Max Repetition

[AGC020D] Min Max Repetition

Score : 11001100 points

Problem Statement

Let f(A,B)f(A, B), where AA and BB are positive integers, be the string satisfying the following conditions:

  • f(A,B)f(A, B) has length A+BA + B;
  • f(A,B)f(A, B) contains exactly AA letters A and exactly BB letters B;
  • The length of the longest substring of f(A,B)f(A, B) consisting of equal letters (ex., AAAAA or BBBB) is as small as possible under the conditions above;
  • f(A,B)f(A, B) is the lexicographically smallest string satisfying the conditions above.

For example, f(2,3)f(2, 3) = BABAB, and f(6,4)f(6, 4) = AABAABAABB.

Answer QQ queries: find the substring of f(Ai,Bi)f(A_i, B_i) from position CiC_i to position DiD_i (1-based).

Constraints

  • 1Q1031 \leq Q \leq 10^3
  • 1Ai,Bi5×1081 \leq A_i, B_i \leq 5 \times 10^8
  • 1CiDiAi+Bi1 \leq C_i \leq D_i \leq A_i + B_i
  • DiCi+1100D_i - C_i + 1 \leq 100
  • All input values are integers.

Partial Score

  • 500500 points will be awarded for passing the testset satisfying 1Ai,Bi1031 \leq A_i, B_i \leq 10^3.

Input

Input is given from Standard Input in the following format:

QQ

A1A_1 B1B_1 C1C_1 D1D_1

A2A_2 B2B_2 C2C_2 D2D_2

::

AQA_Q BQB_Q CQC_Q DQD_Q

Output

For each query ii in order of input, print a line containing the substring of f(Ai,Bi)f(A_i, B_i) from position CiC_i to position DiD_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