You have a sequence $a_1, a_2, \ldots, a_n$ of length $n$, consisting of integers between $1$ and $m$. You also have a string $s$, consisting of $m$ characters B.

You are going to perform the following $n$ operations.

At the $i$-th ($1 \le i \le n$) operation, you replace either the $a_i$-th or the $(m + 1 - a_i)$-th character of $s$ with A. You can replace the character at any position multiple times through the operations.

Find the lexicographically smallest string you can get after these operations.

A string $x$ is lexicographically smaller than a string $y$ of the same length if and only if in the first position where $x$ and $y$ differ, the string $x$ has a letter that appears earlier in the alphabet than the corresponding letter in $y$.


-----Input-----

The first line contains the number of test cases $t$ ($1 \le t \le 2000$).

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 50$) — the length of the sequence $a$ and the length of the string $s$ respectively.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the sequence $a$.


-----Output-----

For each test case, print a string of length $m$ — the lexicographically smallest string you can get. Each character of the string should be either capital English letter A or capital English letter B.


-----Examples-----

Input
6
4 5
1 1 3 1
1 5
2
4 1
1 1 1 1
2 4
1 3
2 7
7 5
4 5
5 5 3 5
Output
ABABA
BABBB
A
AABB
ABABBBB
ABABA


-----Note-----

In the first test case, the sequence $a = [1, 1, 3, 1]$. One of the possible solutions is the following.

At the $1$-st operation, you can replace the $1$-st character of $s$ with A. After it, $s$ becomes ABBBB.

At the $2$-nd operation, you can replace the $5$-th character of $s$ with A (since $m+1-a_2=5$). After it, $s$ becomes ABBBA.

At the $3$-rd operation, you can replace the $3$-rd character of $s$ with A. After it, $s$ becomes ABABA.

At the $4$-th operation, you can replace the $1$-st character of $s$ with A. After it, $s$ remains equal to ABABA.

The resulting string is ABABA. It is impossible to produce a lexicographically smaller string.

In the second test case, you are going to perform only one operation. You can replace either the $2$-nd character or $4$-th character of $s$ with A. You can get strings BABBB and BBBAB after the operation. The string BABBB is the lexicographically smallest among these strings.

In the third test case, the only string you can get is A.

In the fourth test case, you can replace the $1$-st and $2$-nd characters of $s$ with A to get AABB.

In the fifth test case, you can replace the $1$-st and $3$-rd characters of $s$ with A to get ABABBBB.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Strong connectivity

Greedy algorithms

Constructive algorithms


Solutions:
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = ['B'] * m
	for i in a:
		if i - 1 < m - i:
			if ans[i - 1] == 'B':
				ans[i - 1] = 'A'
			elif ans[m - i] == 'B':
				ans[m - i] = 'A'
		elif ans[m - i] == 'B':
			ans[m - i] = 'A'
		elif ans[i - 1] == 'B':
			ans[i - 1] = 'A'
	ans = ''.join(ans)
	print(ans)


import sys

def main():

	def _input_numbers():
		return list(map(int, sys.stdin.readline().split()))
	t = int(input())
	for _ in range(t):
		(n, m) = _input_numbers()
		a = _input_numbers()
		line = ['B'] * m
		for i in range(n):
			place = a[i] - 1
			if place >= m // 2:
				place = m - place - 1
			if line[place] == 'B':
				line[place] = 'A'
			else:
				line[m - place - 1] = 'A'
		print(''.join(line))
main()


class Solution:

	def min_str(self, n, m, oper):
		str_arr = ['B' for _ in range(m)]
		for i in oper:
			if i > m // 2:
				i = m - i + 1
			if str_arr[i - 1] == 'A':
				str_arr[m - i] = 'A'
			else:
				str_arr[i - 1] = 'A'
		return ''.join(str_arr)
t = int(input())
for _ in range(t):
	s = Solution()
	(n, m) = [int(i) for i in input().split()]
	oper = [int(i) for i in input().split()]
	print(s.min_str(n, m, oper))


def another_s(n, m, arr):
	st = 'A' + m * 'B'
	brr = list(st)
	for item in arr:
		place = m + 1 - item
		if item < place:
			les = item
			more = place
		else:
			les = place
			more = item
		if brr[les] == 'B':
			brr[les] = 'A'
		else:
			brr[more] = 'A'
	st1 = ''.join(brr[1:m + 1])
	return st1
t = int(input())
for _ in range(0, t):
	nm = list(map(int, input().rstrip().split()))
	n = nm[0]
	m = nm[1]
	arr = list(map(int, input().rstrip().split()))
	response = another_s(n, m, arr)
	print(f'{response}')


def main():
	n = int(input())
	for _ in range(n):
		(n, m) = map(int, input().split())
		b = ['B'] * m
		a = list(map(int, input().split()))
		for j in range(len(a)):
			if a[j] - 1 <= m - a[j]:
				if b[a[j] - 1] != 'A':
					b[a[j] - 1] = 'A'
				else:
					b[m - a[j]] = 'A'
			elif b[m - a[j]] != 'A':
				b[m - a[j]] = 'A'
			else:
				b[a[j] - 1] = 'A'
		print(''.join(b))
main()


def solve():
	(n, m) = map(int, input().split(' '))
	lst = list(map(int, input().split(' ')))
	s = ['B'] * m
	for i in lst:
		if i <= m + 1 - i:
			if s[i - 1] == 'B':
				s[i - 1] = 'A'
			else:
				s[m - i] = 'A'
		elif s[m - i] == 'B':
			s[m - i] = 'A'
		else:
			s[i - 1] = 'A'
	print(''.join(s))
t = int(input())
while t:
	t -= 1
	solve()


def int_input():
	a = int(input())
	return a

def int_list_input():
	a = list(map(int, input().split()))
	return a

def solve():
	(n, m) = int_list_input()
	arr = int_list_input()
	ans = ['B' for _ in range(m)]
	for i in arr:
		if i - 1 < m - i:
			if ans[i - 1] != 'A':
				ans[i - 1] = 'A'
			else:
				ans[m - i] = 'A'
		elif ans[m - i] != 'A':
			ans[m - i] = 'A'
		else:
			ans[i - 1] = 'A'
	print(''.join(ans))
for _ in range(int(input())):
	solve()


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	string = ['B'] * m
	for i in a:
		if i <= m // 2:
			if string[i - 1] == 'B':
				string[i - 1] = 'A'
			else:
				string[m - i] = 'A'
		elif string[m - i] == 'B':
			string[m - i] = 'A'
		else:
			string[i - 1] = 'A'
	print(''.join(string))


def lex_smallest():
	(n, m) = list(map(int, input().split()))
	array = list(map(int, input().split()))
	string = ['B'] * m
	for i in array:
		ind = m + 1 - i
		if i <= ind and string[i - 1] == 'B':
			string[i - 1] = 'A'
		elif i <= ind and string[i - 1] == 'A':
			string[ind - 1] = 'A'
		if ind < i and string[ind - 1] == 'B':
			string[ind - 1] = 'A'
		elif ind < i and string[ind - 1] == 'A':
			string[i - 1] = 'A'
	fin_string = ''.join(string)
	return fin_string
for case in range(int(input())):
	print(lex_smallest())


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	s = ['B'] * (m + 1)
	for i in range(n):
		a = lst[i]
		if a > m + 1 - a:
			a = m + 1 - a
		if s[a] == 'B':
			s[a] = 'A'
		elif s[m + 1 - a] == 'B':
			s[m + 1 - a] = 'A'
		else:
			continue
	ans = ''.join(s[1:])
	print(ans)


from sys import stdin
test_case = int(stdin.readline())
for i in range(test_case):
	(n, m) = map(int, stdin.readline().split())
	line = map(int, stdin.readline().split())
	output = list(m * 'B')
	s1 = output.copy()
	for j in line:
		a = j
		b = m + 1 - a
		if a > b:
			(a, b) = (b, a)
		if s1[a - 1] == 'A':
			s1[b - 1] = 'A'
		else:
			s1[a - 1] = 'A'
	print(''.join(s1))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = map(int, input().split())
	s = m * ['B']
	for x in a:
		i = x - 1
		j = m - x
		if i > j:
			(i, j) = (j, i)
		if s[i] != 'A':
			s[i] = 'A'
		else:
			s[j] = 'A'
	print(''.join(s))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	result = ['B'] * m
	for i in s:
		i -= 1
		if m - i - 1 >= i:
			if result[i] == 'B':
				result[i] = 'A'
			else:
				result[m - i - 1] = 'A'
		elif result[m - i - 1] == 'B':
			result[m - i - 1] = 'A'
		else:
			result[i] = 'A'
	print(''.join(result))


t = int(input())
while t:
	t -= 1
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	l = list(map(int, input().split()))
	l1 = ['B'] * (m + 1)
	for e in l:
		if l1[e] == 'A':
			l1[m + 1 - e] = 'A'
		elif l1[m + 1 - e] == 'A':
			l1[e] = 'A'
		else:
			l1[min(e, m + 1 - e)] = 'A'
	print(''.join(l1[1:]))


def solution(n, m, arr):
	string = list('B' * m)
	for i in arr:
		if i < m + 1 - i:
			if string[i - 1] == 'A':
				string[m - i] = 'A'
			else:
				string[i - 1] = 'A'
		elif string[m - i] == 'A':
			string[i - 1] = 'A'
		else:
			string[m - i] = 'A'
	return ''.join(string)
N = int(input())
for _ in range(N):
	n = [int(i) for i in input().split(' ')]
	arr = [int(i) for i in input().split(' ')]
	print(solution(n[0], n[1], arr))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = ['B'] * m
	for index in arr:
		if index > m // 2:
			if s[m - index] == 'B':
				s[m - index] = 'A'
			else:
				s[index - 1] = 'A'
		elif s[index - 1] == 'B':
			s[index - 1] = 'A'
		else:
			s[m - index] = 'A'
	print(''.join(s))


T = int(input())
for t in range(T):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ans = ['B' for i in range(m)]
	for id in a:
		if id <= m // 2:
			if ans[id - 1] == 'B':
				ans[id - 1] = 'A'
			else:
				ans[m - id] = 'A'
		elif ans[m - id] == 'B':
			ans[m - id] = 'A'
		else:
			ans[id - 1] = 'A'
	print(''.join(ans))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = ['B'] * m
	arr = list(map(int, input().split()))
	k = len(s)
	for i in arr:
		if s[i - 1] != 'A' and s[k - i] != 'A':
			if i - 1 < k - i:
				s[i - 1] = 'A'
			else:
				s[k - i] = 'A'
		elif s[i - 1] == 'A':
			s[k - i] = 'A'
		else:
			s[i - 1] = 'A'
	print(''.join(s))


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ['B'] * m
	for i in a:
		one = i - 1
		two = m - i
		if one < two:
			if s[one] == 'B':
				s[one] = 'A'
			else:
				s[two] = 'A'
		elif s[two] == 'B':
			s[two] = 'A'
		else:
			s[one] = 'A'
	print(''.join(s))


def solution(a, n, m):
	s = ['B'] * (m + 1)
	for i in range(n):
		first = a[i]
		second = m + 1 - a[i]
		if first > second:
			(first, second) = (second, first)
		if s[first] == 'B':
			s[first] = 'A'
		else:
			s[second] = 'A'
	return ''.join(s[1:])
t = int(input())
answer = [None] * t
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	answer[i] = solution(a, n, m)
print(*answer, sep='\n')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = list('B' * m)
	a = list(map(int, input().split()))
	for i in a:
		if s[i - 1] == 'A':
			s[m - i] = 'A'
		else:
			s[i - 1 if i - 1 < m - i or s[m - i] == 'A' else m - i] = 'A'
	print(''.join(s))


def Dist():
	nm = input().split()
	nm = list(map(int, nm))
	n = nm[0]
	m = nm[1]
	a = input().split()
	a = list(map(int, a))
	B_array = ['B' for _ in range(m)]
	for i in range(n):
		j = a[i] - 1
		if j > m - j - 1:
			j = m - j - 1
		if B_array[j] != 'A':
			B_array[j] = 'A'
		else:
			B_array[m - j - 1] = 'A'
	B_array = ''.join(B_array)
	print(B_array)
num_iter = int(input())
for _ in range(num_iter):
	Dist()


def fun(n, m, a):
	s = ['B' for i in range(m)]
	for i in a:
		if i < m + 1 - i and s[i - 1] != 'A':
			s[i - 1] = 'A'
		elif m + 1 - i - 1 < m and s[m + 1 - i - 1] != 'A':
			s[m + 1 - i - 1] = 'A'
		else:
			s[i - 1] = 'A'
	print(''.join(s))
N = int(input())
l = []
while N > 0:
	N = N - 1
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = list(map(int, input().split()))
	l.append([n, m, a])
for i in l:
	fun(i[0], i[1], i[2])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ['B'] * m
	for i in a:
		indx = i - 1
		indz = m - i
		if indx < indz:
			if s[indx] == 'B':
				s[indx] = 'A'
			else:
				s[indz] = 'A'
		elif s[indz] == 'B':
			s[indz] = 'A'
		else:
			s[indx] = 'A'
	print(''.join(s))


import sys
input = sys.stdin.readline
t = int(input())
for t in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = m * ['B']
	for num in a:
		if num - 1 <= m - num and s[num - 1] != 'A' or (num - 1 >= m - num and s[m - num] == 'A'):
			s[num - 1] = 'A'
		else:
			s[m - num] = 'A'
	print(''.join(s))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = ['B'] * b
	for i in l:
		(n, m) = (i - 1, b - i)
		if n < m:
			if l1[n] == 'B':
				l1[n] = 'A'
			else:
				l1[m] = 'A'
		elif l1[m] == 'B':
			l1[m] = 'A'
		else:
			l1[n] = 'A'
	print(''.join(l1))


T = int(input())

def minimize_str(m, arr):
	s = ['B'] * m
	for i in arr:
		a = i
		b = m + 1 - i
		if a < b:
			small = a
			large = b
		else:
			small = b
			large = a
		if s[small - 1] == 'B':
			s[small - 1] = 'A'
		else:
			s[large - 1] = 'A'
	return ''.join(s)
for t in range(T):
	(_, m) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	print(minimize_str(m, arr))


for _ in ' ' * int(input()):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	p = ['B'] * m
	s = m // 2
	for a in x:
		if a <= s:
			if p[a - 1] == 'B':
				p[a - 1] = 'A'
			else:
				p[-a] = 'A'
		elif p[m - a] == 'B':
			p[m - a] = 'A'
		else:
			p[a - 1] = 'A'
	print(''.join(p))


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = ['B'] * m
	for i in range(n):
		if a[i] < m - a[i] + 1:
			if b[a[i] - 1] == 'B':
				b[a[i] - 1] = 'A'
			else:
				b[m - a[i]] = 'A'
		elif b[m - a[i]] == 'B':
			b[m - a[i]] = 'A'
		else:
			b[a[i] - 1] = 'A'
	print(''.join(b))
for _ in range(int(input())):
	solve()


case = int(input())
for i in range(case):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = ['B' for t in range(m)]
	for t in l:
		if t <= m + 1 - t:
			if s[t - 1] != 'A':
				s[t - 1] = 'A'
			else:
				s[m + 1 - t - 1] = 'A'
		elif s[m + 1 - t - 1] != 'A':
			s[m + 1 - t - 1] = 'A'
		else:
			s[t - 1] = 'A'
	print(''.join(s))


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = ['B'] * m
	com = b.copy()
	for i in a:
		ind1 = i - 1
		ind2 = m - i
		if ind1 > ind2:
			(ind1, ind2) = (ind2, ind1)
		if b[ind1] == 'B':
			b[ind1] = 'A'
		elif b[ind2] == 'B':
			b[ind2] = 'A'
	print(''.join((str(x) for x in b)))
for _ in range(0, int(input())):
	solve()


cases = int(input())
for i in range(cases):
	arr = input().split()
	numberMoves = int(arr[0])
	sizeB = int(arr[1])
	sequence = ['B'] * sizeB
	indexesMoved = input().split()
	indexesMoved = list(map(int, indexesMoved))
	for k in indexesMoved:
		if k - 1 < sizeB - k:
			if sequence[k - 1] != 'A':
				sequence[k - 1] = 'A'
			else:
				sequence[sizeB - k] = 'A'
		elif k - 1 > sizeB - k:
			if sequence[sizeB - k] != 'A':
				sequence[sizeB - k] = 'A'
			else:
				sequence[k - 1] = 'A'
		else:
			sequence[k - 1] = 'A'
	print(''.join(sequence))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	c = ['B'] * m
	for j in map(int, input().split()):
		x = j - 1
		y = m - j
		if x < y:
			if c[x] == 'B':
				c[x] = 'A'
			else:
				c[y] = 'A'
		elif c[y] == 'B':
			c[y] = 'A'
		else:
			c[x] = 'A'
	print(''.join(c))


def miis():
	return map(int, input().split())
for _ in range(int(input())):
	(n, m) = miis()
	a = list(miis())
	ans = ['B' for i in range(m)]
	for i in a:
		if ans[i - 1] == 'B' and (not (m - i < i - 1 and ans[-i] == 'B')):
			ans[i - 1] = 'A'
		else:
			ans[-i] = 'A'
	print(''.join(ans))


def main():
	for t in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		s = ['B' for i in range(m + 1)]
		for i in range(n):
			if s[a[i]] == 'A':
				s[m + 1 - a[i]] = 'A'
				continue
			if s[m + 1 - a[i]] == 'A':
				s[a[i]] = 'A'
				continue
			if a[i] <= m + 1 - a[i]:
				s[a[i]] = 'A'
			else:
				s[m + 1 - a[i]] = 'A'
		print(''.join(s[1:]))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = ['B'] * m
	for num in map(int, input().split()):
		num = min(num, m + 1 - num)
		if s[num - 1] == 'A':
			s[m - num] = 'A'
		else:
			s[num - 1] = 'A'
	print(''.join(s))


t = int(input())
ans = list()
for i in range(0, t):
	(n, m) = map(int, input().split())
	arr = map(int, input().split())
	s = m * ['B']
	for j in arr:
		if j <= (m + 1) / 2:
			if s[j - 1] == 'B':
				s[j - 1] = 'A'
			else:
				s[m - j] = 'A'
		elif s[m - j] == 'B':
			s[m - j] = 'A'
		else:
			s[j - 1] = 'A'
	ans.append(''.join(s))
for s in ans:
	print(s)


out = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = ['B'] * m
	for i in range(n):
		(i1, i2) = sorted([a[i] - 1, m - a[i]])
		if s[i1] == 'B':
			s[i1] = 'A'
		elif s[i2] == 'B':
			s[i2] = 'A'
	out.append(''.join(s))
for i in out:
	print(i)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	s = ['B'] * m
	for i in range(len(a)):
		if a[i] - 1 < m - a[i]:
			if s[a[i] - 1] == 'B':
				s[a[i] - 1] = 'A'
			else:
				s[m - a[i]] = 'A'
		elif s[m - a[i]] == 'B':
			s[m - a[i]] = 'A'
		else:
			s[a[i] - 1] = 'A'
	print(''.join(s))


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	s = ['B'] * m
	for num in arr:
		idx1 = num - 1
		idx2 = m - idx1 - 1
		if idx1 > idx2:
			(idx1, idx2) = (idx2, idx1)
		if s[idx1] == 'A':
			s[idx2] = 'A'
		else:
			s[idx1] = 'A'
	print(''.join(s))


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	inp = list(map(int, input().split()))
	res = ['B'] * m
	for i in inp:
		k = min(i - 1, m - i)
		if res[k] == 'A':
			res[m - k - 1] = 'A'
		else:
			res[k] = 'A'
	print(''.join(res))


def solve(n, m, arr):
	s = ['B' for i in range(m)]
	for i in range(len(arr)):
		if arr[i] < m + 1 - arr[i]:
			if s[arr[i] - 1] == 'A':
				s[m + 1 - arr[i] - 1] = 'A'
			else:
				s[arr[i] - 1] = 'A'
		elif s[m + 1 - arr[i] - 1] == 'A':
			s[arr[i] - 1] = 'A'
		else:
			s[m + 1 - arr[i] - 1] = 'A'
	return ''.join(s)

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		arr = list(map(int, input().split()))
		val = solve(n, m, arr)
		print(val)
main()


def update(string, operation, m):
	for i in operation:
		if i < m + 1 - i:
			if string[i - 1] == 'A':
				string[m + 1 - i - 1] = 'A'
			else:
				string[i - 1] = 'A'
		elif string[m + 1 - i - 1] == 'A':
			string[i - 1] = 'A'
		else:
			string[m + 1 - i - 1] = 'A'
for t in range(int(input())):
	arr = [int(x) for x in input().split()]
	n = arr[0]
	m = arr[1]
	operation = [int(x) for x in input().split()]
	string = ['B'] * m
	update(string, operation, m)
	result = ''
	for i in string:
		result += i
	print(result)


import sys
printf = sys.stdout.write

def intput():
	return int(sys.stdin.readline())

def get_int():
	return map(int, sys.stdin.readline().strip().split())

def get_lis():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_liss():
	return sys.stdin.readline().split()

def get_ints():
	return sys.stdin.readline().split()

def get_str():
	return sys.stdin.readline().strip()

def pop_zeros(items):
	while items[-1] == 0:
		items.pop()
from collections import defaultdict
import math
t = intput()
while t:
	(n, m) = get_int()
	l = get_lis()
	lans = ['B'] * m
	for i in range(n):
		if l[i] < m + 1 - l[i]:
			if lans[l[i] - 1] != 'A':
				lans[l[i] - 1] = 'A'
			elif lans[l[i] - 1] == 'A':
				lans[m - l[i]] = 'A'
		elif lans[m - l[i]] != 'A':
			lans[m - l[i]] = 'A'
		elif lans[m - l[i]] == 'A':
			lans[l[i] - 1] = 'A'
	printf(''.join((str(x) for x in lans)))
	printf('\n')
	t -= 1


def solve(l, m):
	final = {}
	l.sort()
	for x in l:
		a = x
		b = m + 1 - x
		if a > b:
			(a, b) = (b, a)
		if a not in final:
			final[a] = 1
		elif b not in final:
			final[b] = 1
	return final
q = int(input())
for x in range(q):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	arr = solve(l, m)
	ns = ''
	for i in range(m):
		if i + 1 in arr:
			ns += 'A'
		else:
			ns += 'B'
	print(ns)


from collections import defaultdict, Counter, OrderedDict, deque
from heapq import heapify, heappop, heappush

def func():
	(n, m) = map(int, input().split())
	s = ['B' for _ in range(m)]
	arr = list(map(int, input().split()))
	seen = set()
	for i in arr:
		if i not in seen:
			if m + 1 - i < i and m + 1 - i not in seen:
				s[m - i] = 'A'
				seen.add(m + 1 - i)
			else:
				s[i - 1] = 'A'
				seen.add(i)
		elif m + 1 - i not in seen:
			s[m - i] = 'A'
			seen.add(m + 1 - i)
	print(''.join(s))
tc = int(input())
while tc > 0:
	func()
	tc -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	ar = ['B' for i in range(m)]
	for i in s:
		if i <= m // 2:
			if ar[i - 1] != 'A':
				ar[i - 1] = 'A'
			else:
				ar[-i] = 'A'
		elif ar[-i] != 'A':
			ar[-i] = 'A'
		else:
			ar[i - 1] = 'A'
	print(''.join(ar))


def solve(arr, n, m):
	strbit = ['B' for i in range(m)]
	for j in arr:
		a = j
		b = m + 1 - j
		if a < b:
			if a > m:
				continue
			elif strbit[a - 1] == 'B':
				strbit[a - 1] = 'A'
			else:
				strbit[b - 1] = 'A'
		elif b > m:
			continue
		elif strbit[b - 1] == 'B':
			strbit[b - 1] = 'A'
		else:
			strbit[a - 1] = 'A'
	return ''.join(strbit)
for i in range(int(input())):
	(n, m) = input().split()
	arr = list(map(int, input().split()))
	print(solve(arr, int(n), int(m)))


for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	li = list(map(int, input().split(' ')))
	s = ['B'] * (m + 1)
	s[0] = '0'
	for i in li:
		if s[i] == 'B' and s[m + 1 - i] == 'B':
			if i > m + 1 - i:
				s[m + 1 - i] = 'A'
			else:
				s[i] = 'A'
		elif s[i] == 'A' and s[m + 1 - i] == 'B':
			s[m + 1 - i] = 'A'
		else:
			s[i] = 'A'
	s.pop(0)
	print(''.join(s))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	res = ['B'] * m
	for i in arr:
		if i <= int((m + 1) // 2) and res[i - 1] == 'B':
			res[i - 1] = 'A'
		elif res[m - i] == 'B':
			res[m - i] = 'A'
		else:
			res[i - 1] = 'A'
	print(''.join(res))


t = int(input())
sol = []
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) - 1 for x in input().split()]
	s = ['B'] * m
	for ai in a:
		if s[min(ai, m - ai - 1)] == 'B':
			s[min(ai, m - ai - 1)] = 'A'
		else:
			s[max(ai, m - ai - 1)] = 'A'
	sol.append(''.join(s))
for s in sol:
	print(s)


ans = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = list('B' * m)
	for i in range(n):
		if a[i] - 1 < m - a[i]:
			if s[a[i] - 1] == 'B':
				s[a[i] - 1] = 'A'
			elif s[m - a[i]] == 'B':
				s[m - a[i]] = 'A'
			else:
				s[a[i] - 1] = 'A'
		elif s[m - a[i]] == 'B':
			s[m - a[i]] = 'A'
		elif s[a[i] - 1] == 'B':
			s[a[i] - 1] = 'A'
		else:
			s[a[i] - 1] = 'A'
	ans.append(''.join(s))
print(*ans, sep='\n')


t = int(input())
lst = []
for i in range(t):
	(n, m) = map(int, input().split())
	listik = list(map(int, input().split()))
	st = list('B' * m)
	for i in range(len(listik)):
		if st[listik[i] - 1] == 'B' and (m - listik[i] > listik[i] - 1 or st[m - listik[i]] == 'A'):
			st[listik[i] - 1] = 'A'
		elif st[m - listik[i]] == 'B':
			st[m - listik[i]] = 'A'
	lst.append(''.join(st))
print('\n'.join(lst))


import math
from collections import Counter
from collections import defaultdict
import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def solve(n, m, arr):
	d = {}
	for i in arr:
		minn = min(i, m + 1 - i)
		if minn not in d:
			d[minn] = 1
		elif minn == i:
			d[m + 1 - i] = 1
		else:
			d[i] = 1
	ans = ''
	for i in range(1, m + 1):
		if i in d:
			ans += 'A'
		else:
			ans += 'B'
	return ans
t = int(input())
for _ in range(t):
	(n, m) = get_ints()
	arr = get_ints()
	print(solve(n, m, arr))


t = int(input())
while t > 0:
	t = t - 1
	s = []
	(n, m) = map(int, input().split())
	for i in range(m):
		s.append('B')
	l1 = [int(x) for x in input().split()]
	for i in l1:
		if i < m + 1 - i:
			if s[i - 1] != 'A':
				s[i - 1] = 'A'
			else:
				s[m - i] = 'A'
		elif s[m - i] != 'A':
			s[m - i] = 'A'
		else:
			s[i - 1] = 'A'
	print(''.join(s))


def solve():
	n = input()
	l = list(map(int, n.split(' ')))
	b = input()
	a = list(map(int, b.split(' ')))
	s = []
	j = l[1]
	while j != 0:
		s.append('B')
		j -= 1
	for temp in range(len(a)):
		k1 = a[temp] - 1
		k2 = l[1] - a[temp]
		if k2 < k1:
			temp1 = k1
			k1 = k2
			k2 = temp1
		if s[k1] == 'B':
			s[k1] = 'A'
		elif s[k2] == 'B':
			s[k2] = 'A'
	s1 = ''
	for temp in s:
		s1 += temp
	print(s1)
t = int(input())
while t != 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(n, b) = map(int, input().split())
	l = list(map(int, input().split()))
	s = ['B'] * b
	b -= 1
	for i in l:
		i = i - 1
		d = b - i
		if i < d and s[i] != 'A':
			s[i] = 'A'
		elif s[d] == 'A':
			s[i] = 'A'
		else:
			s[d] = 'A'
	print(''.join(s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = m * 'B'
	lis = list(s)
	for i in a:
		if lis[i - 1] != 'A' and m // 2 >= i or (lis[m - i] == 'A' and m // 2 < i):
			lis[i - 1] = 'A'
		elif lis[i - 1] == 'A' and m // 2 >= i or (lis[m - i] != 'A' and m // 2 < i):
			lis[m - i] = 'A'
	print(''.join(lis))


cases = int(input())

def op(a, m, s):
	for i in range(len(a)):
		poss = m + 1 - a[i]
		if a[i] <= poss:
			if s[a[i] - 1] != 'A':
				s[a[i] - 1] = 'A'
			elif s[a[i] - 1] == 'A':
				s[poss - 1] = 'A'
		elif a[i] > poss:
			if s[poss - 1] != 'A':
				s[poss - 1] = 'A'
			elif s[poss - 1] == 'A':
				s[a[i] - 1] = 'A'
	print(''.join(s))
for _ in range(cases):
	(n, m) = [int(i) for i in input().split()]
	a = list([int(i) for i in input().split()])
	s = ['B'] * m
	op(a, m, s)


for __ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	l1 = []
	s = 'B' * m
	l2 = list(s)
	for z in a:
		t = m + 1 - z
		if z <= t:
			if l2[z - 1] != 'A':
				l2[z - 1] = 'A'
			elif l2[t - 1] != 'A':
				l2[t - 1] = 'A'
		elif l2[t - 1] != 'A':
			l2[t - 1] = 'A'
		elif l2[z - 1] != 'A':
			l2[z - 1] = 'A'
	s = ''.join(l2)
	print(s)


for _ in range(0, int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = list(m * 'B')
	for i in range(0, n):
		(x, y) = (a[i] - 1, m - a[i])
		if x > y:
			(x, y) = (y, x)
		if s[x] == 'B':
			s[x] = 'A'
		else:
			s[y] = 'A'
	print(''.join(s))


t = int(input())
while t:
	(p, q) = map(int, input().split())
	s = list(map(int, input().split()))
	f = ['B'] * q
	for i in s:
		z = min(i, q + 1 - i) - 1
		if f[z] == 'B':
			f[z] = 'A'
		else:
			f[q - z - 1] = 'A'
	print(''.join(f))
	t -= 1


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ['B'] * m
	for i in range(n):
		a_i = min(a[i] - 1, m - a[i])
		if s[a_i] == 'B':
			s[a_i] = 'A'
		else:
			s[m - 1 - a_i] = 'A'
	print(''.join(s))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = [int(i) for i in input().split()]
	s = ['B'] * b
	for i in l:
		if i - 1 < b - i:
			if s[i - 1] == 'B':
				s[i - 1] = 'A'
			else:
				s[b - i] = 'A'
		elif s[b - i] == 'B':
			s[b - i] = 'A'
		else:
			s[i - 1] = 'A'
	s1 = ''
	for i in s:
		s1 = s1 + i
	print(s1)


test = int(input())

def change(array, m):
	result = ['B' for i in range(m)]
	for num in array:
		if num <= m + 1 - num and result[num - 1] != 'A':
			result[num - 1] = 'A'
		elif num <= m + 1 - num:
			result[m - num] = 'A'
		elif num > m + 1 - num and result[m - num] != 'A':
			result[m - num] = 'A'
		else:
			result[num - 1] = 'A'
	return ''.join(result)
for i in range(test):
	[n, m] = list(map(int, input().split()))
	array = list(map(int, input().split()))
	print(change(array, m))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split(' '))
	array = list(map(int, input().split(' ')[:n]))
	ans = ['B'] * m
	for i in array:
		pos1 = i - 1
		pos2 = m - i
		if pos1 <= pos2:
			if ans[pos1] == 'B':
				ans[pos1] = 'A'
			else:
				ans[pos2] = 'A'
		elif ans[pos2] == 'B':
			ans[pos2] = 'A'
		else:
			ans[pos1] = 'A'
	print(''.join(ans))
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	string = ['B' for i in range(m)]
	for i in range(n):
		p1 = arr[i] - 1
		p2 = m - arr[i]
		if string[p1] == 'B':
			if string[p2] == 'B' and p2 < p1:
				string[p2] = 'A'
			else:
				string[p1] = 'A'
		else:
			string[p2] = 'A'
	print(''.join(string))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = list(map(int, input().split()))
	l = ['B'] * b
	for i in n:
		x = min(i - 1, b - i)
		if l[x] == 'A':
			l[b - x - 1] = 'A'
		else:
			l[x] = 'A'
	print(''.join(l))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ['B'] * m
	for i in a:
		if i < m + 1 - i:
			if s[i - 1] == 'B':
				s[i - 1] = 'A'
			else:
				s[m - i] = 'A'
		elif i > m + 1 - i:
			if s[m - i] == 'B':
				s[m - i] = 'A'
			else:
				s[i - 1] = 'A'
		else:
			s[i - 1] = 'A'
	f = ''
	for i in s:
		f = f + i
	print(f)


k = int(input())
for j in range(k):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = 'B' * m
	brr = list(brr)
	for i in arr:
		if i - 1 < m - i:
			if brr[i - 1] == 'B':
				brr[i - 1] = 'A'
			else:
				brr[m - i] = 'A'
		elif brr[m - i] == 'B':
			brr[m - i] = 'A'
		else:
			brr[i - 1] = 'A'
	print(''.join(map(str, brr)))


def main(t):
	for _ in range(t):
		(n, m) = map(int, input().split())
		arr = [min(int(x) - 1, m - int(x)) for x in input().split()]
		result = ['B' for _ in range(m)]
		for x in arr:
			if result[x] == 'A':
				result[m - 1 - x] = 'A'
			else:
				result[x] = 'A'
		print(''.join(result))
main(int(input()))


a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	e = 'B' * c
	e = list(e[:])
	for f in d:
		if e[f - 1] == 'B' and e[c - f] == 'B':
			if f - 1 < c - f:
				e[f - 1] = 'A'
			else:
				e[c - f] = 'A'
		elif e[f - 1] == 'B' or e[c - f] == 'B':
			e[f - 1] = 'A'
			e[c - f] = 'A'
	e = ''.join(e)
	print(e)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	out = {i: 'B' for i in range(1, m + 1)}
	for a in arr:
		if m + 1 - a < a and out[m + 1 - a] == 'B':
			out[m + 1 - a] = 'A'
		elif out[a] == 'B':
			out[a] = 'A'
		elif out[m + 1 - a] == 'B':
			out[m + 1 - a] = 'A'
	b = ''.join(list(out.values()))
	print(b)


import sys, math

def get_line_ints(stream):
	return [int(x) for x in next(lines).rstrip().split(' ')]
lines = sys.stdin
n_cases = get_line_ints(lines)[0]
for case_ndx in range(n_cases):
	(n, m) = get_line_ints(lines)
	int_list = get_line_ints(lines)
	string = ['B'] * m
	assert len(int_list) == n
	for i in int_list:
		i = min(i, m - i + 1)
		if string[i - 1] == 'B':
			string[i - 1] = 'A'
		else:
			string[m - i] = 'A'
	print(''.join(string))


t = int(input())
for j in range(t):
	nm = list(map(int, input().split()))
	(n, m) = (nm[0], nm[1])
	a_seq = list(map(int, input().split()))
	s = ['B' for i in range(m)]
	result = ''
	for i in a_seq:
		if s[i - 1] == 'B' and s[m - i] == 'B':
			if i - 1 <= m - i:
				s[i - 1] = 'A'
			else:
				s[m - i] = 'A'
			continue
		elif s[i - 1] == 'B':
			s[i - 1] = 'A'
			continue
		elif s[m - i] == 'B':
			s[m - i] = 'A'
			continue
	print(''.join(s))


def answer():
	test_case_num = int(input())
	for i in range(test_case_num):
		(n, m) = input().split()
		seq = input().split()
		for (i, j) in enumerate(seq):
			seq[i] = int(j)
		n = int(n)
		m = int(m)
		string = list('B' * m)
		for i in seq:
			if string[i - 1] == 'B' and i - 1 < len(string) / 2:
				string[i - 1] = 'A'
			elif string[len(string) - i] == 'B':
				string[len(string) - i] = 'A'
			else:
				string[i - 1] = 'A'
		out = ''
		for c in string:
			out = out + c
		print(out)
answer()


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	s = 'B' + 'B' * m
	a = [*map(int, input().split())]
	s = list(s)
	for i in range(n):
		if s[a[i]] == 'B' and s[m + 1 - a[i]] == 'B':
			s[min(a[i], m + 1 - a[i])] = 'A'
		elif s[a[i]] == 'A':
			s[m + 1 - a[i]] = 'A'
		elif s[m + 1 - a[i]] == 'A':
			s[a[i]] = 'A'
	print(''.join(s)[1:])


def fun(m, a):
	d = set()
	for j in a:
		i = j - 1
		an = m - i - 1
		if i in d or an in d:
			d.add(i)
			d.add(an)
		else:
			d.add(min(i, an))
	ans = [0] * m
	for i in range(m):
		if i in d:
			ans[i] = 'A'
		else:
			ans[i] = 'B'
	return ''.join(ans)
for _ in range(int(input())):
	(_1, m) = input().split()
	m = int(m)
	a = input().split()
	a = list(map(int, a))
	print(fun(m, a))


def solve():
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	ans = ['B'] * m
	for i in lis:
		(one, two) = (min(i, m + 1 - i), max(i, m + 1 - i))
		if ans[one - 1] == 'B':
			ans[one - 1] = 'A'
		else:
			ans[two - 1] = 'A'
	print(''.join(ans))
for _ in range(int(input())):
	solve()


def main():
	len = int(input())
	for i in range(len):
		x = [int(j) for j in input().split()]
		n = x[0]
		m = x[1]
		out = ''
		for k in range(m):
			out += 'B'
		out = list(out)
		arr = [int(j) for j in input().split()]
		for j in range(n):
			if arr[j] < m + 1 - arr[j] and out[arr[j] - 1] == 'B':
				out[arr[j] - 1] = 'A'
			elif m + 1 - arr[j] <= m and out[m - arr[j]] == 'B':
				out[m - arr[j]] = 'A'
			else:
				out[arr[j] - 1] = 'A'
		out = ''.join(out)
		print(out)
main()


def func():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(m):
		b.append('B')
	for i in range(len(a)):
		pos1 = a[i] - 1
		pos2 = m + 1 - a[i] - 1
		if pos1 < pos2 or pos2 < 0:
			if b[pos1] == 'B':
				b[pos1] = 'A'
			else:
				b[pos2] = 'A'
		elif b[pos2] == 'B':
			b[pos2] = 'A'
		else:
			b[pos1] = 'A'
	print(''.join(b))
	return
t = int(input())
for i in range(t):
	func()


t = int(input())
vet = []
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	st = ['B'] * m
	for i in range(n):
		aux = a[i] - 1
		aux2 = m - a[i]
		item = min(aux, aux2)
		if st[item] != 'B':
			st[m - item - 1] = 'A'
		else:
			st[item] = 'A'
	vet.append(''.join(st))
print(*vet, sep='\n')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ['B'] * m
	for i in range(n):
		(i1, i2) = (a[i] - 1, m - a[i])
		if i1 < i2:
			if s[i1] == 'A':
				s[i2] = 'A'
			else:
				s[i1] = 'A'
		elif i1 > i2:
			if s[i2] == 'A':
				s[i1] = 'A'
			else:
				s[i2] = 'A'
		else:
			s[i1] = 'A'
	print(''.join(s))


T = int(input())
for i in range(T):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = ['B' for i in range(m)]
	for ind in arr:
		i = min(ind, m - ind + 1)
		if s[i - 1] == 'B':
			s[i - 1] = 'A'
		else:
			s[m - i] = 'A'
	print(''.join(s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	c = ['B'] * m
	for i in a:
		if i < m + 1 - i:
			if c[i - 1] != 'A':
				c[i - 1] = 'A'
			else:
				c[m + 1 - i - 1] = 'A'
		elif m + 1 - i <= m:
			if c[m + 1 - i - 1] != 'A':
				c[m + 1 - i - 1] = 'A'
			else:
				c[i - 1] = 'A'
	print(''.join(c))