/+ dub.sdl:
    name "D"
    dependency "dunkelheit" version=">=0.9.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;

long[2][] aDiv(long a, long dist, long cnt) {
    if (a == cnt) return [[1, cnt]];
    long[2][] al;
    long af = (a-cnt) / (dist-1);
    al ~= [dist, af];
    a -= dist*af; cnt -= af;
    if (cnt == 0) return al;
    al ~= [a - cnt + 1, 1];
    a -= (a-cnt+1); cnt -= 1;
    al ~= [1, a];
    return al;
}

long[2][] bDiv(long b, long dist, long cnt) {
    auto u = aDiv(b, dist, cnt);
    u.reverse;
    return u;
}

string calc(long a, long b, long c, long d) {
    long l = 0, r = max(a, b);
    long amin, amax, bmin, bmax;
    void fill(long md) {
        amin = (a+md-1)/md;
        amax = a;
        bmin = (b+md-1)/md;
        bmax = b;
    }
    while(r-l > 1) {
        long md = (l+r)/2;
        fill(md);
        bool f = true;
        if (amax < bmin-1) f = false;
        if (bmax < amin-1) f = false;
        if (!f) {
            l = md;
        } else {
            r = md;
        }
    }
    fill(r);

//    writeln("FIND ", r, " ", amin, " ", amax, " ", bmin, " ", bmax);

    long[2][] al, bl;
    if (bmin == amax+1) {
        //bbbabbbabbbabbb
        al = [0, 1] ~ aDiv(a, r, amax);
        bl = bDiv(b, r, bmin);
    } else if (amin == bmax+1) {
        al = aDiv(a, r, amin);
        bl = bDiv(b, r, bmax) ~ [0, 1];
    } else {
        amin = bmin = max(amin, bmin);
        amax = bmax = min(amax, bmax);
        long z = r;
        l = amin-1, r = bmax;
        while (r-l > 1) {
            long md = (l+r)/2;
            long af = (a-md) / (z-1);
            long bf = md - (b-md + z-2) / (z-1);
            if (af - bf >= 2) {
//            if (af > bf) {
                l = md;
            } else if (af - bf == 1) {
                if ((a - md) % (z-1) == 0) {
                    r = md;
                } else {
                    l = md;
                }
            } else {
                r = md;
            }
        }
//        writeln("result ", l, " ", r);
        al = aDiv(a, z, r);
        bl = bDiv(b, z, r);
    }
//    writeln(al, " ", bl);

    long m = al.map!"a[1]".sum;

    long cnt(long[2][] li, long u) {
        long sm = 0;
        foreach (d; li) {
            if (u <= d[1]) return sm + d[0]*u;
            sm += d[0]*d[1];
            u -= d[1];
        }
        return u;
    }
    long[2][] skip(long[2][] _li, long u) {
        long[2][] li = _li;
        while (u) {
            if (li[0][1] == 0) {
                li = li[1..$];
                continue;
            }
            if (u <= li[0][1]) {
                li[0][1] -= u;
                break;
            }
            u -= li[0][1];
            li[0][1] = 0;
        }
        return li;
    }
    l = 0, r = m;
    while (r-l > 1) {
        long md = (l+r)/2;
        long z = cnt(al, md) + cnt(bl, md);
        if (z <= c) {
            l = md;
        } else {
            r = md;
        }
    }
    long z = cnt(al, l) + cnt(bl, l);
    c -= z; d -= z;
    al = skip(al, l);
    bl = skip(bl, l);

    string s;
    void add(char ch) {
        if (c <= 0 && 0 < d) s ~= ch;
        c--; d--;
    }
    void addS(long A, long B) {
        if (c > 0) {
            long u = min(c, A);
            c -= u; d -= u; A -= u;
        }
        foreach (i; 0..A) {
            add('A');
            if (d <= 0) break;
        }
        if (c > 0) {
            long u = min(c, B);
            c -= u; d -= u; B -= u;
        }
        foreach (i; 0..B) {
            add('B');
            if (d <= 0) break;
        }
    }
    while (0 < d) {
        while (al[0][1] == 0) al = al[1..$];
        while (bl[0][1] == 0) bl = bl[1..$];
        addS(al[0][0], bl[0][0]);
        al[0][1]--; bl[0][1]--;
    }
    return s;
}


int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) sc.read!true;
    int q;
    sc.read(q);
    foreach (_; 0..q) {
        long a, b, c, d;
        sc.read(a, b, c, d); c--;
        writeln(calc(a, b, c, d));
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

 
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

     
    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
    
    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }  
    ref inout(T) front() inout { return this[0]; }  
    ref inout(T) back() inout { return this[$-1]; }  

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }  
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }  
     
    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }  
    alias opOpAssign(string op : "~") = insertBack;  
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }  
}

 
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */
 
// module dkh.foundation;

 
static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }
     
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

 
class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                 
                 
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
    void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
        import std.exception;
        enforce(readSingle(x));
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            read!enforceEOF(args);
        }
    }
    void read(bool enforceEOF = false, Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            enforce(readSingle(args[0]));
            read!enforceEOF(args);
        }
    }
}


 
 

 

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/
