Language: C++

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskD solver = new TaskD();
    int testCount = Integer.parseInt(in.next());
    for (int i = 1; i <= testCount; i++) {
      solver.solve(i, in, out);
    }
    out.close();
  }

  static class TaskD {

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int a = in.nextInt();
      int b = in.nextInt();
      int l = in.nextInt() - 1;
      int r = in.nextInt() - 1;

      int s;
      if (a >= b) {
        s = a / (b + 1);
        if (a % (b + 1) != 0) {
          ++s;
        }
        Assert.assertTrue(s * (b + 1) >= a);

        int numSab = Math.min(b, a / s);
        while (numSab > 0 && bad(a - numSab * s - 1, b - numSab, s)) {
          --numSab;
        }
        a -= numSab * s;
        b -= numSab;
        for (int i = l; i <= r; ++i) {
          if (i < numSab * (s + 1)) {
            int j = i % (s + 1);
            if (j < s) {
              out.print('A');
            } else {
              out.print('B');
            }
          } else {
            int j = i - numSab * (s + 1);
            if (j < a) {
              out.print('A');
            } else {
              out.print('B');
            }
          }
        }
        out.printLine();
      } else {
        s = b / (a + 1);
        if (b % (a + 1) != 0) {
          ++s;
        }
        Assert.assertTrue(s * (a + 1) >= b);

        int numSab = (int) ((a * (long) s + s - b) / Math.max(1, s * (long) s - 1));
        numSab += 2;
        if (numSab > (a - 1) / s) {
          numSab = (a - 1) / s;
        }
        if (numSab > b) {
          numSab = b;
        }
        while (numSab > 0 && div(b - numSab, a + 1 - s * (long) numSab - 1) > s) {
          --numSab;
        }

        a -= s * numSab;
        b -= numSab;

        int start = a - b / s + 2;
        if (start > a) {
          start = a;
        }
        if (start > s) {
          start = s;
        }
        while (div(b, a + 1 - start) > s) {
          --start;
        }
        for (int i = l; i <= r; ++i) {
          if (i < numSab * (s + 1)) {
            out.print(i % (s + 1) == s ? 'B' : 'A');
            continue;
          }
          int i0 = i - numSab * (s + 1);
          if (i0 < start) {
            out.print('A');
          } else {
            int j = (i0 - start) % (s + 1);
            if (j == s) {
              out.print('A');
            } else {
              out.print('B');
            }
          }
        }
        out.printLine();
      }
    }

    private boolean bad(long a, long b, long s) {
      if (a < 0 || b < 0) {
        return true;
      }
      if (a == 0) {
        return b <= s;
      }
      if (b == 0) {
        return a <= s;
      }
      if (div(a, b + 1) > s) {
        return true;
      }
      if (div(b, a + 1) > s) {
        return true;
      }
      return false;
    }

    private long div(long a, long b) {
      long r = a / b;
      if (a % b != 0) {
        ++r;
      }
      return r;
    }

  }

  static class Assert {

    public static void assertTrue(boolean flag) {
//        if (!flag)
//        while (true);
      if (!flag) {
        throw new AssertionError();
      }
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public static boolean isSpace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
      if (count == -1) {
        throw new InputMismatchException();
      }
      try {
        if (cur >= count) {
          cur = 0;
          count = stream.read(buffer);
          if (count <= 0) {
            return -1;
          }
        }
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      return buffer[cur++];
    }

    public int readSkipSpace() {
      int c;
      do {
        c = read();
      } while (isSpace(c));
      return c;
    }

    public String nextToken() {
      int c = readSkipSpace();
      StringBuilder sb = new StringBuilder();
      while (!isSpace(c)) {
        sb.append((char) c);
        c = read();
      }
      return sb.toString();
    }

    public String next() {
      return nextToken();
    }

    public int nextInt() {
      int sgn = 1;
      int c = readSkipSpace();
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res = res * 10 + c - '0';
        c = read();
      } while (!isSpace(c));
      res *= sgn;
      return res;
    }

  }

  static class OutputWriter {

    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }
}



Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.OutputStream;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.IOException;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.InputStream;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.io.OutputStream;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.io.PrintWriter;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.io.BufferedWriter;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.util.InputMismatchException;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import java.io.IOException;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import java.io.Writer;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'import' does not name a type
   10 | import java.io.OutputStreamWriter;
      | ^~~~~~
a.cc:10:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'import' does not name a type
   11 | import java.io.InputStream;
      | ^~~~~~
a.cc:11:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:18:1: error: expected unqualified-id before 'public'
   18 | public class Main {
      | ^~~~~~