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
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <numeric>
using namespace std;

using ll = long long;

int main() {
    vector<string> magic{"AP", "AAPP", "AAAPAPPP"};
    int z;
    cin >> z;
    while (z--) {
        int n, k;
        cin >> n >> k;
        if (k <= 3) {
            if (n <= magic[k-1].size()) cout << magic[k-1].substr(0, n);
            else cout << "NIE";
        } else {
            cout << string(k-2, 'A');
            for (int i = 0; i < n - k + 2; i++) cout << "AAPAPP"[i % 6];
        }
        cout << endl;
    }
    return 0;
}