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 <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <complex>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int Q;
	cin >> Q;
	REP(i, Q){
		int a, b, c, d;
		int ca, cb;
		cin >> a >> b >> c >> d;
		ca = a; cb = b;
		string s = "";
		vector<int> A, B;
		int k = max(a, b)/min(a, b);
		bool f = 0;
		if(a < b){
			swap(a, b);
			f = 1;
		}
		while(min(ca, cb)){
			if(a >= b){
				A.push_back(k); ca -=k;
				if(a%b){
					ca--;
					A[A.size()-1]++;
				}
				B.push_back(1); cb -=1;
			}else{
				B.push_back(k); cb-=k;
				A.push_back(1); ca-=1;
			}
		}
		if(b > a && cb >= k){
			B.push_back(k); cb-=k;
		}

		REP(i, ca){
			A[i]++;
		}
		for(int i = B.size()-1;i >= B.size()-cb;i--){
			B[i]++;
		}
		REP(i, A.size()){
			if(A.size() >= B.size()){
				s += string(A[i], 'A');
				s += string(B[i], 'B');
			}else{
				s += string(B[i], 'B');
				s += string(A[i], 'A');
			}
		}
		if(A.size()>B.size())
			s += string(A[A.size()-1], 'A');
		if(B.size()>A.size())
			s += string(B[B.size()-1], 'B');
		if(f){
			reverse(all(s));
			FOR(i, c-1, d){
				if(s[i] == 'A')
					cout << 'B';
				else
					cout << 'A';
			}
			cout << endl;
		}
		cout << s.substr(c-1, d-c+1) << endl;
	}
}