Language: C++

#include <algorithm>
#include <cctype>
#include <cstring>
#define fi first
#define se second
#define N 100005
 
using namespace std;
typedef long long ll;
 
template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}
 
inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}
 
const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }
 
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll) res * x % mod;
		x = (ll) x * x % mod, y >>= 1;
	} return res;
}
 
template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
 
int q, A, B, C, D;
 
int main() {
	q = input();
	while (q--) {
		A = input(), B = input(), C = input(), D = input();
		int n = A + B, len = (max(A, B) - 1) / (min(A, B) + 1) + 1;
		int l = 0, r = n + 1, mid, ans = n + 1;
		while (l <= r) {
			mid = (l + r) >> 1;
			int a = A - mid / (len + 1) ;
			int b = B - mid / (len + 1);
			if (b <= (ll) a * len) l = mid + 1;
			else r = mid - 1, ans = mid;
		}
		int a = A - ans / (len + 1) * len - ans % (len + 1);
		int b = B - ans / (len + 1), P = ans + b - a * len + 1;
		for (int i = C; i <= min(D, ans); ++i) putchar(i % (len + 1) ? 'A' : 'B');
		for (int i = max(C, ans + 1); i <= D; ++i) putchar(abs(P - i) % (len + 1) ? 'B' : 'A');
		putchar('\n');
	}
	return 0;
}

Compiler output:
a.cc: In function 'void read(T&)':
a.cc:13:30: error: there are no arguments to 'getchar' that depend on a template parameter, so a declaration of 'getchar' must be available [-fpermissive]
   13 |         while (!isdigit(ch = getchar())) flag |= ch == '-';
      |                              ^~~~~~~
a.cc:13:30: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:14:40: error: there are no arguments to 'getchar' that depend on a template parameter, so a declaration of 'getchar' must be available [-fpermissive]
   14 |         for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
      |                                        ^~~~~~~
a.cc: In function 'int input()':
a.cc:20:30: error: 'getchar' was not declared in this scope
   20 |         while (!isdigit(ch = getchar())) flag |= ch == '-';
      |                              ^~~~~~~
a.cc:4:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    3 | #include <cstring>
  +++ |+#include <cstdio>
    4 | #define fi first
a.cc:21:40: error: 'getchar' was not declared in this scope
   21 |         for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
      |                                        ^~~~~~~
a.cc:21:40: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In function 'int main()':
a.cc:58:56: error: 'putchar' was not declared in this scope; did you mean 'u_char'?
   58 |                 for (int i = C; i <= min(D, ans); ++i) putchar(i % (len + 1) ? 'A' : 'B');
      |                                                        ^~~~~~~
      |                                                        u_char
a.cc:59:60: error: 'putchar' was not declared in this scope; did you mean 'u_char'?
   59 |                 for (int i = max(C, ans + 1); i <= D; ++i) putchar(abs(P - i) % (len + 1) ? 'B' : 'A');
      |                                                            ^~~~~~~
      |                                                            u_char
a.cc:60:17: error: 'putchar' was not declared in this scope; did you mean 'u_char'?
   60 |                 putchar('\n');
      |                 ^~~~~~~
      |                 u_char