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
t = int(input())

for _ in range(t):
    n, k = map(int, input().split())

    if k == 1 and n > 2:
        print("NIE")
    elif k == 1 and n == 1:
        print("A")
    elif k == 1 and n == 2:
        print("PA")
    elif k == n:
        print(k*"A")
    elif k >= n/2:
        print(k*"A" + (n-k)*"P")
    elif k == 2:
        if n == 2:
            print("AA")
        elif n == 3:
            print("AAP")
        elif n == 4:
            print("AAPP")
        
    else:
        napis = k * 'A' + (k-2) * 'P' + "AP" + (k-2) * 'A' + k * 'P'

        if k + k + k - 2 + k < n:
            print("NIE")
            continue

        print(napis[:n])