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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back
#define fi first
#define se second
#define each(a,x) for(auto &a:x)
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define nl '\n'
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC target("bmi")
#pragma GCC target("bmi2")
#pragma GCC target("lzcnt")
#pragma GCC target("popcnt")
const int N = 5e5+1234,INF = 2e9+1234,mod = 1e9+7;
const ll INF_L = (ll)2e18+1234;
void solve()
{
    int n,k;cin>>n>>k;
    if(k==1 and n==1){cout << "P" << nl;return;}
    else if(k==1 and n==2){cout << "PA" << nl;return;}
    else if(k==1){cout << "NIE" << nl;return;}
    else if(k==2)
    {
        string A="PPAA";
        if(n<=4) rep(i,n) cout << A[i];
        else cout << "NIE";
        cout << nl; return;
    }
    else if(k==3)
    {
        string A="AAAPAPPP";
        if(n<=8) rep(i,n) cout << A[i];
        else cout << "NIE";
        cout << nl; return;
    }
    else
    {
        rep(i,k) cout << "P";
        n-=k;
        rep(i,n)
        {
            if(i%6==0 or i%6==1 or i%6==3) cout << "A";
            else cout << "P";
        }
        cout << nl;return;
    }
}
int main()
{ 
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    cin >> T;
    while(T--) solve();
    return 0;
}