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
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
// head

const int N=1e6+5;

#define INF 0x3f3f3f3f

template<class T> inline void read(T &x) {
    x=0; int c=getchar(),f=1;
    for (;!isdigit(c);c=getchar()) if (c==45) f=-1;
    for (;isdigit(c);c=getchar()) (x*=10)+=f*(c-'0');
}

char ans[N],bridge[6]="PAPPA",filler[7]="APAPPA";

int main() {
    int t;
    scanf("%d",&t);
    while (t--) {
        int n,k;
        scanf("%d%d",&n,&k);
        if (k==1&&n>2||k==2&&n>4||k==3&&n>8) {
            puts("NIE");
            continue;
        }
        if (k==1) {
            if (n==1) strcpy(ans,"A");
            else strcpy(ans,"AP");
        } else if (k==2) {
            if (n==2) strcpy(ans,"AA");
            else if (n==3) strcpy(ans,"AAP");
            else strcpy(ans,"AAPP");
        } else if (k==3) {
            strcpy(ans,"AAA");
            rep(i,3,n) {
                for (char c:{'A','P'}) {
                    ans[i]=c;
                    bool ok=true;
                    if (i>=3) {
                        bool flag=true;
                        rep(j,0,2) if (ans[i-3+j]!=ans[i-j]) {
                            flag=false;
                            break;
                        }
                        if (flag) ok=false;
                    }
                    if (ok&&i>=4) {
                        bool flag=true;
                        rep(j,0,2) if (ans[i-4+j]!=ans[i-j]) {
                            flag=false;
                            break;
                        }
                        if (flag) ok=false;
                    }
                    if (ok) break;
                }
            }
        } else {
            int ptr=0;
            for (int i=0;i<k&&ptr<n;i++) ans[ptr++]='A';
            for (int i=0;i<5&&ptr<n;i++) ans[ptr++]=bridge[i];
            int i=0;
            while (ptr<n) {
                ans[ptr++]=filler[i];
                i=(i+1)%6;
            }
        }
        ans[n]='\0';
        printf("%s\n",ans);
    }
}