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

using namespace std;
typedef long long ll;

void gen(int n, int k){

    if (k==1) { if (n>2) cout<<"NIE"; if (n<=2) cout<<string("AP").substr(0,n); }
    if (k==2) { if (n>4) cout<<"NIE"; if (n<=4) cout<<string("AAPP").substr(0,n); }
    if (k==3) { if (n>8) cout<<"NIE"; if (n<=8) cout<<string("AAAPAPPP").substr(0,n); }
    if (k>=4) {
        for (auto i=1;i<=k;i++) cout<<"A";
        n-=k;
        while (n>6) {cout<<"PAPPAA"; n-=6;}
        if (n>0) cout<<string("PAPPAA").substr(0,n);
    }
    cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T, n, k;
    cin >> T;
    for (auto t=1; t<=T; t++) {
        cin>>n>>k;
        gen(n,k);
    }
    return 0;
}