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

using namespace std;

#define int long long

string PRE[11][4] = {
    {"","","",""},
    {"","A","",""},
    {"","AP","AA",""},
    {"","NIE","AAP","AAA"},
    {"","NIE","AAPP","AAAP"},
    {"","NIE","NIE","AAAPA"},
    {"","NIE","NIE","AAAPAP"},
    {"","NIE","NIE","AAAPAPP"},
    {"","NIE","NIE","AAAPAPPP"},
    {"","NIE","NIE","NIE"},
    {"","NIE","NIE","NIE"}
};

void solve(){
    int n, k; cin>>n>>k;
    if(k <= 3){
        if(n > 10){
            cout<<"NIE\n";
        }else{
            cout<<PRE[n][k] << "\n";
        }
    }else{
        string res;
        res.reserve(n);
        for(int i=0; k>i; i++){
            res += 'A';
        }
        string xd = "PAPPAA";
        for(int i=k; n>i; i++){
            res += xd[(i - k) % 6];
        }
        cout<<res<<"\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt; cin>>tt;
    while(tt-->0){
        solve();
    }
}