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<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

bool solve(int a, int b, int k){
	if(b > a) return !solve(b, a, a + b - 1 - k);
	
	/*
	AAABAAAB...AAAで最後a足りなくなったらbbabbbabbb
	*/
	int len = (a + b) / (b + 1);
	int lo = 0, hi = b + 1, mid;
	
	auto ok = [&](int m){
		if(a < (ll)m * len + 1) return false;
		int ra = a - m * len;
		int rb = b - m;
		return (rb + len - 1) / len <= ra;
	};
	
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		if(ok(mid)) lo = mid;
		else hi = mid;
	}
	
	int rb = b - lo;
	int it = (rb + len - 1) / len;
	int ra = a - lo * len - max(0, it - 1);
	
	/*
	string s;
	rep(i, lo) s += string(len, 'A') + 'B';
	s += string(ra, 'A');
	rep(i, it){
		s += string(rb / it + (i >= it - rb % it), 'B');
		if(i != it - 1) s += 'A';
	}
	dbg(lo, len, it, ra, rb); dbg(s);
	*/
	
	if(k < (len + 1ll) * lo) return k % (len + 1) == len;
	k -= (len + 1) * lo;
	if(k < ra) return 0;
	k -= ra;
	if(k < (rb / it + 1) * (it - rb % it)) return k % (rb / it + 1) != rb / it;
	k -= (rb / it + 1) * (it - rb % it);
	return k % (rb / it + 2) != rb / it + 1;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	while(n--){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		assert(a <= 1000 && b <= 1000);
		for(int i = c - 1; i < d; i++) cout << char('A' + solve(a, b, i));
		cout << endl;
	}
	
	return 0;
}