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
#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
template<typename T1,typename T2>auto& operator<<(ostream&o,pair<T1,T2>a){return o<<"("<<a.first<<", "<<a.second<<")";}
template<typename T,size_t...I>void pt(ostream&o,T t,index_sequence<I...>){o<<"(";(...,(o<<(I?", ":"")<< get<I>(t)));o<<")";}
template<typename...A>auto& operator<<(ostream&o,tuple<A...>t){pt(o,t,index_sequence_for<A...>{});return o;}
template<typename T,typename O>auto& operator<<(O&o,T a){o<<"{";for(auto b:a)o<<b<<", ";return o<<"}";}
#define db(x...) cerr << "\033[92m" << "[" #x "]: ", [](auto... args) { ((cerr << args << ", "),...) << "\033[0m" << "\n"; }(x)
#else
#define db(...)
#endif

#define sz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()
#define F first
#define S second

template<class T>
using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using vi = vector<int>;

mt19937 mrand(random_device{}());
ll rnd(ll l, ll r) { return l + mrand() % (r - l + 1);}

int main() {
    cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);

    ll t;
    cin >> t;
    while(t--) {
        ll n, k; cin >> n >> k;
        if(k == 1) {
            if(n==1) cout << "P\n";
            else if(n==2) cout << "PA\n";
            else cout << "NIE\n";
        }
        else if (k == 2) {
            if(n==2) cout << "PP\n";
            else if(n==3) cout << "PPA\n";
            else if(n==4) cout << "PPAA\n";
            else cout << "NIE\n";
        } else if(k == 3) {
            if(n==3) cout << "PPP\n";
            else if(n==4) cout << "PPPA\n";
            else if(n==5) cout << "PPPAP\n";
            else if(n==6) cout << "PPPAPA\n";
            else if(n==7) cout << "PPPAPAA\n";
            else if(n==8) cout << "PPPAPAAA\n";
            else cout << "NIE\n";
        } else {
            string pattern = "PPAPAA";
            for(ll i = 0 ; i < k ; ++i) cout << "P";
            for(ll i = 0 ; i < n-k ; ++i) cout << pattern[(i+2)%6];
            cout << "\n";
        }
    }

    return 0;
}