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
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;

int n, k;

string seq1 = "APAAPP";
string seq2 = "AAAPAPPP";

void solve() {
    cin >> n >> k;

    if (k >= 4) {
        rep(i, k) cout << "P";
        rep(i, n-k) cout << seq1[i%6];
        cout << "\n";
    } else if (k == 3) {
        if (n <= 8) {
            rep(i, n) cout << seq2[i];
            cout << "\n";
        } else cout << "NIE\n";
    } else if (k == 2) {
        if (n == 2) cout << "AA\n";
        else if (n == 3) cout << "AAP\n";
        else if (n == 4) cout << "AAPP\n";
        else cout << "NIE\n";
    } else if (k == 1) {
        if (n == 1) cout << "A\n";
        else if (n == 2) cout << "AP\n";
        else cout << "NIE\n";
    }
}


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int t;
    cin >> t;
    while (t--) solve();

    return 0;
}