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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <bits/stdc++.h>

using namespace std;

#define st first
#define nd second
#define pb push_back
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define irep(i,a,b) for(int i = a; i >= b; i--)
typedef long long ll;
typedef long double ld;
//typedef __int128 int128;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi; 
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;


int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    //A - 0, P - 1
    string wzor = "AAPAPP";
    string t1 = "AAPP";
    string t2 = "PPPAPAAA";

    int t; cin >> t;
    while(t--){

        int n,k;
        cin >> n >> k;

        if(n >= 9 && k < 4){
            cout << "NIE\n";
            continue;
        }
        if(n >= 5 && k < 3){
            cout << "NIE\n";
            continue;
        }
        if(n >= 3 && k < 2){
            cout << "NIE\n";
            continue;
        }

        if(k == 1 && n == 1){
            cout << "P\n";
            continue;
        }
        if(k == 1 && n == 2){
            cout << "PA\n";
            continue;
        }

        if(k == 2){
            for(int i = 0; i < n; i++) cout << t1[i];
            cout << '\n';
            continue;
        }
        if(k == 3){
            for(int i = 0; i < n; i++) cout << t2[i];
            cout << '\n';
            continue;
        }

        for(int i = 1; i <= k; i++) cout << "P";
        int ind = 0;
        for(int i = k+1; i <= n; i++){
            cout << wzor[ind];
            ind++;
            if(ind == 6) ind = 0;
        }
        cout << '\n';
    

    }

    return 0;
}

//g++ -O3 -static -Wall .cpp -std=c++17