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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1e9+7;

void solve() {
    int n, k; cin >> n >> k;
    if (n <= 10) {
        for (int mask = 0; mask < (1<<n); mask++) {
            auto palindrome = [&](int l, int r){
                while (l < r) {
                    if (((mask>>l)&1) != ((mask>>r)&1)) return false;
                    l++;
                    r--;
                }
                return true;
            };
            int curr = 0;
            for (int l = 0; l < n; l++) {
                for (int r = l; r < n; r++) {
                    if (palindrome(l, r)) {
                        curr = max(curr, r - l + 1);
                    }
                }
            }
            if (curr == k) {
                for (int i = 0; i < n; i++) {
                    if (mask & (1 << i)) cout << 'P';
                    else cout << 'A';
                }
                cout << "\n";
                return;
            }
        }
        cout << "NIE\n";
        return;
    }
    
    if (k <= 3) {
        cout << "NIE\n";
        return;
    }
    string s = "PAPPAA";
    for (int i = 0; i < k; i++) cout << 'A';
    for (int i = 0; i < n - k; i++) {
        cout << s[i % 6];
    }
    cout << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while (t--) solve();
}
/*
1
11 4
PPAAPAPAAAA
*/