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
#include <bits/stdc++.h>
#define F(i, a, b) for(int i = (a); i <= (b); i++)
#define pb push_back
#define be(X) X.begin(), X.end()
#define V vector
#define f first
#define s second
using namespace std;

string s1 = "PA";
string s2 = "PPAA";
string s3 = "PPPAPAAA";
string rep = "APAAPP";

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

    if(k == 1){
        if(n <= 2) cout << s1.substr(0, n) << "\n";
        else cout << "NIE\n";
        return;
    }

    if(k == 2){
        if(2 <= n && n <= 4) cout << s2.substr(0, n) << "\n";
        else cout << "NIE\n";
        return;
    }

    if(k == 3){
        if(3 <= n && n <= 8) cout << s3.substr(0, n) << "\n";
        else cout << "NIE\n";
        return;
    }

    string ans = "";
    
    F(i, 1, k){
        ans += 'P';
    }

    F(i, 0, n - k-1){
        ans += rep[i % 6];
    }

    cout << ans << "\n";
}

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

    int t;
    cin >> t;

    while(t--){
        solve();
    }
}