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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void solve() {
    int n, k;
    if (!(cin >> n >> k)) return;

    if (k == 1) {
        if (n >= 3) {
            cout << "NIE" << endl;
        } else {
            string res = "";
            for (int i = 0; i < n; ++i) {
                res += (i % 2 == 0 ? 'P' : 'A');
            }
            cout << res << endl;
        }
        return;
    }

    string res = "";
    for (int i = 0; i < k; ++i) res += 'A';
    
    if (n > k) {
        res += 'P';
        for (int i = k + 1; i < n; ++i) {
            res += (i % 2 == (k + 1) % 2 ? 'A' : 'P');
        }
    }

    auto check = [&](const string& s, int max_k) {
        int actual_max = 0;
        int size = s.length();
        for (int i = 0; i < size; ++i) {
            for (int j = 0; i - j >= 0 && i + j < size; ++j) {
                if (s[i - j] == s[i + j]) actual_max = max(actual_max, 2 * j + 1);
                else break;
            }
            for (int j = 0; i - j >= 0 && i + j + 1 < size; ++j) {
                if (s[i - j] == s[i + j + 1]) actual_max = max(actual_max, 2 * j + 2);
                else break;
            }
        }
        return actual_max == max_k;
    };

    if (k >= 2) {
        cout << res << endl;
    } else {
        cout << "NIE" << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    if (!(cin >> t)) return 0;
    while (t--) {
        solve();
    }
    return 0;
}