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
#include <bits/stdc++.h>
using namespace std;

const string opt[3] = {"AP", "AAPP", "AAAPAPPP"};
const string repeat = "PAPPAA";

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	for (int r = 0; r < t; r++) {
		int n;
		int q;
		cin >> n >> q;

		if (n < q) {
			cout << "NIE\n";
			continue;
		}
		if (q <= 3) {
			string op = opt[q-1];
			if (n > op.length()) {
				cout << "NIE\n";
				continue;
			}
			for (int i = 0; i < n; i++) {
				cout << op[i];
			}
			cout << "\n";
			continue;
		}

		for (int i = 0; i < q; i++) {
			cout << 'A';
		}
		for (int i = 0; i < n - q; i++) {
			cout << repeat[i % repeat.length()];
		}
		cout << "\n";
	}
}