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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <stack>
using namespace std;
stack<int>stos;
void generuj(int ile,int k)
{
    int war=0;
    for(int i=1;i<=k;i++){
        stos.push(war);
    }
    ile-=k;
    int nr=1;
    while(ile>0){
        war^=1;
        if(nr%4==1||nr%4==2){
            stos.push(war);
            ile--;
        }
        else{
            if(ile==1){
                stos.push(war);
                ile--;
            }
            else{
                stos.push(war);
                stos.push(war);
                ile-=2;
            }
        }
        nr++;
    }
}
void wypisz_string()
{
    while(!stos.empty()){
        if(stos.top()==0){
            cout<<'A';
        }
        else{
            cout<<'P';
        }
        stos.pop();
    }
    cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int ile,k;
        cin>>ile>>k;
        if(k>=4){
            generuj(ile,k);
            wypisz_string();
        }
        else if(ile>8&&k<4){
            cout<<"NIE"<<"\n";
        }
        else{
            if(ile<=8&&ile>=5){
                if(k<3){
                    cout<<"NIE"<<"\n";
                }
                else{
                    if(ile==8){
                        cout<<"PPPAPAAA"<<"\n";
                    }
                    else if(ile==7){
                        cout<<"PPAPAAA"<<"\n";
                    }
                    else if(ile==6){
                        cout<<"PAPAAA"<<"\n";
                    }
                    else{
                        cout<<"PAPPP"<<"\n";
                    }
                }
            }
            else if(ile<=4&&ile>=3){
                if(ile==4&&k==3){
                    cout<<"PAAA"<<"\n";
                }
                else if(ile==4&&k==2){
                    cout<<"PPAA"<<"\n";
                }
                else if(ile==3&&k==3){
                    cout<<"PPP"<<"\n";
                }
                else if(ile==3&&k==2){
                    cout<<"PAA"<<"\n";
                }
                else{
                    cout<<"NIE"<<"\n";
                }
            }
            else{
                if(ile==2&&k==2){
                    cout<<"PP"<<"\n";
                }
                else if(ile==2&&k==1){
                    cout<<"PA"<<"\n";
                }
                else{
                    cout<<"P"<<"\n";
                }
            }
        }
    }



    return 0;
}