1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
import itertools as it


def czypal(slowo,s,d):
    e = s + d - 1
    while s < e:
        if slowo[s] != slowo[e]:
            return False
        s += 1
        e -= 1

    return True

def czyjestpal(slowo,d):
    for i in range(len(slowo) - d + 1):
        if czypal(slowo, i, d):
            return True
    return False
            
    
    
def analfabeta(t):
    n = int(t[0])
    k = int(t[1])
    for slowo in map(''.join, it.product("AP", repeat=n)):
        if not czyjestpal(slowo, k):
            continue
        if czyjestpal(slowo, k + 1):
            continue
        if czyjestpal(slowo, k + 2):
            continue
        return slowo
    return "NIE"


danie = sys.stdin
#danie = open("danie.txt", "r")
p = danie.readline()
for i in range(int(p)):
    t = danie.readline().split()
    print(analfabeta(t))