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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>


using namespace std;


const string BLOCK = "PPAAPA";

int maxPal(int n, const string &s) {
    int ans = 1;
    for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
        int len = j - i + 1;
        if (len <= ans) {
            continue;
        }

        bool isPal = true;
        for (int k = 0; k < len; k++) {
            if (s[i + k] != s[j - k]) {
                isPal = false;
                break;
            }
        }

        if (isPal) {
            ans = len;
        }
    }

    return ans;
}

string solve(int n, int k) {
    if (k <= 3) {
        if (n >= 9) {
            return "NIE";
        } else {
            for (int mask = 0; mask < (1 << n); mask += 2) {
                string word(n, ' ');
                for (int i = 0; i < n; i++) {
                    word[i] = (mask & (1 << i)) ? 'P' : 'A';
                }

                if (maxPal(n, word) == k) {
                    return word;
                }
            }

            return "NIE";
        }
    } else {
        string s = string(k - 2, 'P');
        while (s.size() < n) {
            s += BLOCK;
        }

        s.resize(n);
        return s;
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    int t;
    cin >> t;

    while (t--) {
        int n, k;
        cin >> n >> k;

        cout << solve(n, k) << '\n';
    }

    return 0;
}