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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<class T>
using vec = vector<T>;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef KoRoVa
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif

const int max_n = -1, inf = 1000111222;



void test_case() {
    int n, k;
    cin >> n >> k;
    if (n == k) {
        cout << string(n, 'A') << '\n';
        return;
    }
    if (k == 1) {
        if (n == 2) {
            cout << "AP\n";
            return;
        }
        cout << "NIE\n";
        return;
    }
    if (k == 2) {
        if (n == 3) {
            cout << "AAP\n";
            return;
        }
        if (n == 4) {
            cout << "AAPP\n";
            return;
        }
        cout << "NIE\n";
        return;
    }
    if (k == 3) {
        if (n > 8) {
            cout << "NIE\n";
            return;
        }
        if (n <= 6) {
            cout << "AAA" << string(n - 3, 'P') << '\n';
            return;
        }
        if (n == 7) {
            cout << "AAAPAPP\n";
            return;
        }
        assert(n == 8);
        cout << "AAAPAPPP\n";
        return;
    }

    int res = k;
    string ans(res, 'A');
    while (len(ans) < n) {
        ans += "PAPPAA"; // xd
    }
    ans.resize(n);
    cout << ans << '\n';
}

mt19937 rng(228);
template<typename T = int>
inline T randll(T l = INT_MIN, T r = INT_MAX) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline ld randld(ld l = INT_MIN, ld r = INT_MAX) {
    return uniform_real_distribution<ld>(l, r)(rng);
}



int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);


//    auto calc = [&] (int n) {
//        int c = 0;
//        int mn = inf;
//        while (c < (1 << n)) {
//            string s;
//            int x = c++;
//            for (int i = 0; i < n; i++) {
//                s += "01"[x % 2];
//                x /= 2;
//            }
//            int mx = 1;
//            auto pal = [&] (int i, int j) {
//                while (i < j) {
//                    if (s[i] != s[j]) {
//                        return false;
//                    }
//                    ++i;
//                    --j;
//                }
//                return true;
//            };
//            for (int i = 0; i < n; i++) {
//                for (int j = i; j < n; j++) {
//                    if (pal(i, j)) {
//                        umax(mx, j - i + 1);
//                    }
//                }
//            }
//            if (umin(mn, mx)) {
//                LOG(n, mx, s);
////            getchar();
//            }
//        }
//        LOG(n, mn);
//        return mn;
//    };
//    int n = 9;
//
//    for (int i = 1; i <= 20; i++) {
//        calc(i);
//    }
//    calc(27);

    int t = 1;

     cin >> t;

    while (t--) test_case();

    return 0;
}

/*
KoRoVa!
*/