Problem:
Score : 1100 points

Problem Statement

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

f(A, B) has length A + B;

f(A, B) contains exactly A letters A and exactly B letters B;

The length of the longest substring of f(A, B) consisting of equal letters (ex., AAAAA or BBBB) is as small as possible under the conditions above;

f(A, B) is the lexicographically smallest string satisfying 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).

Constraints

1 \leq Q \leq 10^3

1 \leq A_i, B_i \leq 5 \times 10^8

1 \leq C_i \leq D_i \leq A_i + B_i

D_i - C_i + 1 \leq 100

All input values are integers.

Partial Score

500 points will be awarded for passing the testset satisfying 1 \leq A_i, B_i \leq 10^3.

Input

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

Output

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).

Sample Input 1

5
2 3 1 5
6 4 1 10
2 3 4 4
6 4 3 7
8 10 5 8

Sample Output 1

BABAB
AABAABAABB
A
BAABA
ABAB

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

// f(2, 3) := BABAB
// f(6, 4) := AABAABAABB
// f(2, 4) := ABBABB
// f(3, 5) := ABBABBAB

// g(A, B) := length item 3;
int g(int a, int b) {
    if (a < b) swap(a, b);
    return (a+b) / (b+1);
}

int A, B, C, D;

void MAIN() {
    scanf("%d%d%d%d", &A, &B, &C, &D);
    C--;

    int z = g(A, B);
    // a(z), a(z), ..., a(A%z);
    // b(B%z), b(z), b(z), ...;
    
    LL lo = 0, hi = min(A/z, B)+1;
    while (hi - lo > 1) {
	LL mid = (lo + hi) / 2;
	LL ta = A-mid*z;
	LL tb = B-mid;
	bool ok;
	if (ta == 0) ok = false;
	else ok = (g(ta - 1, tb) <= z);
	(ok? lo: hi) = mid;
    }

    LL L = lo;
    // a(z)b * L;

    LL R = min(A-z*L, (B-L)/z);

    LL MA = A - z*L - R;
    LL MB = B - L - z*R;

    int len = D - C;
    string ans;
    if (D <= (z+1)*L) {
	int left = 0;
	string tmp;
	while (left + z + 1 <= C) left += z+1;
	int pos = left;
	while (pos < D) {
	    tmp += string(z, 'A') + "B";
	    pos += z+1;
	}
	ans = tmp.substr(C - left, len);
    } else if ((z+1)*L+MA+MB <= C) {
	int left = (z+1)*L + MA + MB;
	string tmp;
	while (left + z + 1 <= C) left += z+1;
	int pos = left;
	while (pos < D) {
	    tmp += string(1, 'A') + string(z, 'B');
	    pos += z+1;
	}
	ans = tmp.substr(C - left, len);
    } else {
	int left = (z+1)*L; 
	string tmp;
	while (C < left) {
	    tmp += string(z, 'A') + "B";
	    left -= z+1;
	}
	if ((z+1)*L + MA <= C) left += MA;
	else tmp += string(min(len, (int)MA), 'A');
	if ((z+1)*L + MA + MB <= C) left += MB;
	else tmp += string(min(len, (int)MB), 'B');

	int right = left + MA + MB;
	while (right < D) {
	    tmp += string(1, 'A') + string(z, 'B');
	    right += z+1;
	}
	ans = tmp.substr(C - left, len);
    }

    cout << ans << endl;
    
//    lo = 1; hi = min(z+1, A-L*z+1);
//    while (hi - lo > 1) {
//	LL mid = (lo + hi) / 2;
//	LL ta = A-L*z-mid;
//	if (g(ta, B-L) > z) hi = mid;
//	else lo = mid;
//    }
//    LL MA = lo;
//    // a
//    
//    LL TA = A-L*z-MA;
//    LL TB = B-L;
//    LL lo = 0, hi = min(TA, TB/z)+1;
//    while (hi - lo > 1) {
//	LL mid = (lo + hi) / 2;
//	LL ta = TA-mid;
//	LL tb = TB-mid*z;
//	bool ok;
//	if (tb == 0) ok = false;
//	else ok = (g(ta, tb) <= z);
//    }

}


int main() {
    int TC = 1;
    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}