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
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t,i,j,n,k;cin>>t;
    for(i=0;i<t;++i){
        cin>>n>>k;
        if((n+1)/2<=k){
            for(j=0;j<k;++j)cout<<"A";
            for(j=k;j<n;++j)cout<<"P";
        }
        else if(n>2 && k==1)cout<<"NIE";
        else if(n==2 && k==1)cout<<"AP";
        else if(2*k+(k-1)/2+1>=n && ((k-1)/2)>0){
            for(j=0;j<k;++j)cout<<"A";
            j=k+1;cout<<"P";int c=0;
            while(c<(k-1)/2){cout<<"A";++c;}
            j+=c;
            while(j<n){cout<<"P";++j;}
        }
        else if(k>3){
        for(j=0;j<k;++j)cout<<"A";
    string s="PPAPAA";
    for (j =0;j<n-k;++j)cout<<s[j%6];}
            else cout<<"NIE";
        cout<<'\n';
    }
    return 0;
}